enable rand(::AbstractArray, [dims])

This is a rewrite of 6d329ce, 9d0282e and d9814ff (from #8309,
which was reverted).