Julia random numbers

Played around with generating random numbers in Julia.

Not a hugely important topic, however it leads me to a complaint about the documentation! This was originally a rant but I toned it down after considering this is Version 1.

I’ve noticed that many examples describe using what appears to be a built-in function…when in fact, in this case, a “using Random” MUST BE supplied, but NOT shown in the example.

For example trying out random numbers…I came upon this code (2 lines) which they actually show successfully executing in the REPL…

rng = MersenneTwister(1234);
rand!(rng, zeros(5))

BUT IT DIDN’T SUCCESSFULLY EXECUTE IN MY REPL!!!!!!!!!!!!!!!!!
My REPL responds with…
ERROR: UndefVarError: MersenneTwister not defined

WTH? What is required? What is missing?…

I SEE EXAMPLES LIKE THIS TIME AND TIME AGAIN!

%%% S O L V E D %%%
I guess it boils down to my misunderstanding of the documentation, because earlier they describe the function, but don’t show the “using Random” statement in the example…
Random.rand! — Function.

HOWEVER WHY WOULDN’T YOU JUST SHOW the  ‘using Random’ statement to the 2 lines of code in the example?

Example code [2 lines]…doesn’t work!
rng = MersenneTwister(1234);
rand!(rng, zeros(5))

Code with 1 extra required line[3 lines]…Works!
using Random
rng = MersenneTwister(1234);
rand!(rng, zeros(5))

Julia veterans would understand that “Random” was was not built-in AND beginners could execute the example successfully!!!!

But Nooooo…I have to type it in and have it fail then spend time figuring out why it failed!!!!!!!!!
Like anything new, it’s harder to learn in the beginning, documentation and tutorials improve over time.

2 replies on “Julia random numbers”

  1. Thank you for every other informative blog. Where else
    may I get that type of information written in such
    an ideal way? I’ve a challenge that I am simply now working on, and I have been at the look out for such information.

Comments are closed.