`rand` sampling from an array accepts an optional rng

Fixes #5978.