elm generate random number -


i want generate random int between 2 values in elm. this:

nb = random(0, 10)

i have read doc , multiple post. best answer stackoverflow post

gen = random.int 0 10 seed0 = random.initialseed 123456 random.generate gen seed0 

but issue it's return same value , it's not int it's this:

(7,seed { state = state 645041272 40692, next = <function>, split = <function>, range = <function> }) : ( int, random.seed ) 

so doc, it's better use current time seed. how it? have use signal ? there not easy way timestamp?

i'm lot confuse, need generate random int seed can generate random int. if not random int generated not random. think have misunderstood ...

edit: have found post didn't understand everything.

it's return[ing] same value

this how pure random number generators work. pass in seed, , seed.

and it's not int it's [crazy code snippet]

this pair of values. first int you're looking for. second new seed generate random values. don't worry seed is; should opaque. can int out pair using fst, if want more random numbers, you'll need new seed.

so doc, it's better use current time seed.

this doc wrong, wrong, wrong. you've discovered, there isn't easy way current timestamp. , if you're passing in js, simon advises, use math.floor(math.random()*0xffffffff) instead. gives seed better sampled on possible input space.

this extremely important because random number generator output similar values similar seeds. example, if you use seed less 53668 , generate 1 bool, true. because of weaknesses in algorithm used.

the better solution: --> use library<-- . works same way core library, algorithm better, , docs on seeds aren't blatantly wrong.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -