On Monday, September 12, 2016 at 7:32:48 AM UTC-4, Neal Becker wrote:
>
> PnSeq.jl calls rand() to get a Int64, caching the result and then 
> providing 
> N bits at a time to fill an Array.  It's supposed to be a fast way to get 
> an 
> Array of small-width random integers. 
>

rand(T, n) already does this for small integer types T.  (In fact, it 
generates 128 random bits at a time.)  See base/random.jl 
<https://github.com/JuliaLang/julia/blob/d0e7684dd0ce867e1add2b88bb91f1c4574100e0/base/random.jl#L507-L515>
 
for how it does it.

In a quick test, rand(UInt16, 10^6) was more than 6x faster than 
pnseq(16)(10^6, UInt16).

(In a performance-critical situation where you are calling this lots of 
times to generate random arrays, I would pre-allocate the array A and call 
rand!(A) instead to fill it with random numbers in-place.)

Reply via email to