[erlang-questions] more random uniform

Jachym Holecek freza@REDACTED
Sun Oct 27 15:58:55 CET 2013


# 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