[erlang-questions] more random uniform

Peer Stritzinger <>
Mon Oct 28 14:17:04 CET 2013


If you want to reproduce a sequence you usually store the seed values.

One often seen way to properly do random:seed/1 calls:

<<A:32, B:32, C:32>> = crypto:rand_bytes(12),   random:seed({A,B,C})

Save the values of A, B and C in your data (e.g. beginning of the 
corresponding log or whatever)

Cheers
-- Peer

On 2013-10-27 16:28:24 +0000, Bengt Kleberg said:

> My computer is not available right now, but my understanding is that 
> using now() will make it really hard to reproduce that sequence again.
> 
> 
> 
> Bengt
> 
> 
> Sent from Moxier Mail
> (http://www.moxier.com)
> 
> 
> ----- Ursprungligt meddelande -----
> Från: Evgeny M <>
> Till: "" 
> <>
> Kopia: "" <>, 
> Bengt Kleberg <>
> Skickat: 27-10-2013 4:35 em
> Ämne: Re: [erlang-questions] more random uniform
> 
> 
> 1>  [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 1 
> 
> BUT (now() instead of X, y, 0)
> 
> 2>  [erlang:spawn( fun() -> random:seed(now()), io:fwrite("~p ", 
> [random:uniform(3)]) end ) || X<-lists:seq(1,10), Y<-lists:seq(1,10)]. 
> 1 3 3 2 3 1 2 1 2 3 1 3 1 2 1 3 3 1 1 3 2 1 2 1 3 1 3 2 3 2 3 2 3 1 2 3 
> 2 3 1 2 3 2 1 3 1 2 1 2 1 1 1 1 2 2 3 1 2 3 1 3 2 1 2 3 2 1 3 1 2 1 3 3 
> 2 2 1 3 3 1 2 1 2 2 2 1 1 2 3 2 3 1 2 3 1 3 1 2 3 2 3 2 
> 
> 
> 
> воскресенье, 27 октября 2013 г., 13:45:35 UTC+4 пользователь Bengt 
> Kleberg написал:
> Greetings,
> 
> When doing random:uniform/1 for small values, ie 3, the result is 1 the 
> first time. Changing the seed does not help.
> What am I missing?
> 
> 
> Bengt
> 
> Sent from Moxier Mail
> (http://www.moxier.com)
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions





More information about the erlang-questions mailing list