Random number generation F# -
i have following code:
let rand = system.random() let gold = [ in years yield rand.nextdouble()] however cannot collapse 1 line as
let gold = [ in years yield system.random.nextdouble()] why?
most random numbers generated computers, such in case of code, not random in true sense of word. generated algorithm, , given algorithm , seed (like starting point algorithm), deterministic.
essentially, when want series of random numbers, select seed , algorithm, , algorithm starts generating random numbers using seed starting point , iterating algorithm there.
in old days, people produce books of "random numbers". these books used seed , algorithm produce random series of numbers ahead of time. if wanted random number, select 1 book.
computers work similarly. when call
let rand = system.random() you initializing random number generator. creating book full of random numbers. iteratively draw random numbers series, do
rand.nextdouble() that picking first number series (book). call again , pick second number series, etc.
what point of f#/.net having initialize random number generator? well, if wanted repeatable results random series contain same numbers every time ran code? well, doing way allows set seed guaranteed have same "book of random numbers" each time:
let rand = system.random(1) or, if wanted different series of random numbers?
let rand1 = system.random(1) let rand2 = system.random(2)
Comments
Post a Comment