[erlang-questions] more random uniform
Bengt Kleberg
bengt.kleberg@REDACTED
Sun Oct 27 17:39:46 CET 2013
Would it be better to use seed(O,X,Y) than seed(X,Y,O)?
Or should I multiply them larger?
Bengt
Sent from Moxier Mail
(http://www.moxier.com)
----- Ursprungligt meddelande -----
Från: Jachym Holecek <freza@REDACTED>
Till: Bengt Kleberg <bengt.kleberg@REDACTED>
Kopia: "erlang-questions@REDACTED" <erlang-questions@REDACTED>
Skickat: 27-10-2013 3:56 em
Ämne: Re: [erlang-questions] more random uniform
# Bengt Kleberg 2013-10-27:
>
> 7> [erlang:spawn( fun() -> random:seed(X,Y,0), io:fwrite("~p ", [random:uniform(3)]) end ) || X<-lists:seq(1,10), Y<-lists:seq(1,10)].
> 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Looking at how uniform/0 and uniform/1 work -- with the seed you're supplying
all factors in calculation of R end up something like 0.05, giving R of say
0.16, mapping to (0,1) range is a no-op, times three in uniform/1 resulting
firmly less than 1.0, truncating to zero, adding one and yielding the ones
you're observing.
OTP version doesn't really matter, same results with R11 up to R16, random(3)
probably didn't change drastically over time.
Initializing the seed manually, other than the recommended way, so it gives
good results from the start is beginning to sound a bit tricky...
BR,
-- Jachym
More information about the erlang-questions
mailing list