[erlang-questions] more random uniform

Bengt Kleberg bengt.kleberg@REDACTED
Sun Oct 27 20:36:01 CET 2013


Thank you all.

By using X*1000, Y*1000 and the sum *1000 I got sufficiently random numbers.


Bengt

Sent from Moxier Mail
(http://www.moxier.com)


----- Ursprungligt meddelande -----
Från: Tony Rogvall <tony@REDACTED>
Till: Bengt Kleberg <bengt.kleberg@REDACTED>
Kopia: "erlang-questions@REDACTED" <erlang-questions@REDACTED>
Skickat: 27-10-2013 6:14 em
Ämne: Re: [erlang-questions] more random uniform




No it was not necessary, just making sure it was fresh every time.

Any particular reason to keep the third argument to zero in the random:seed/3 call ?
This will, as you point out, generate an initial sequence of small random:uniform numbers.
Looking at random.erl the calculation is (modified in this context):

(((X+1)*171) rem 30269) / 30269  +
(((Y+1)*172) rem 30307) / 30307 +
(((0+1)*170) rem 30323) / 30323

Keeping the X and Y small enough (less than 176 ) we can rewrite this as:

R = ((X+1)*171) / 30269 + ((Y+1)*172) / 30307 + 170 / 30323

The value of this expression will be small given small values on X and Y,  and the expression
trunc(R*3) will be zero for X+Y < 56 (roughly)

In other words use larger numbers, and use them all, when seeding the random number generator.

/Tony


On 27 okt 2013, at 11:48, Bengt Kleberg <bengt.kleberg@REDACTED<mailto:bengt.kleberg@REDACTED>> wrote:


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


Sent from Moxier Mail
(http://www.moxier.com)


----- Ursprungligt meddelande -----
Från: Bengt Kleberg <bengt.kleberg@REDACTED<mailto:bengt.kleberg@REDACTED>>
Till: null
Kopia: "erlang-questions@REDACTED<mailto:erlang-questions@REDACTED>" <erlang-questions@REDACTED<mailto:erlang-questions@REDACTED>>
Skickat: 27-10-2013 11:33 fm
Ämne: Re: [erlang-questions] more random uniform




Thank you.

I have 15B.
Is the erase/1 necessary? I am using new processes each time.


Bengt

Sent from Moxier Mail
(http://www.moxier.com)


----- Ursprungligt meddelande -----
Från: Tony Rogvall <tony@REDACTED<mailto:tony@REDACTED>>
Till: Bengt Kleberg <bengt.kleberg@REDACTED<mailto:bengt.kleberg@REDACTED>>
Kopia: "erlang-questions@REDACTED<mailto:erlang-questions@REDACTED>" <erlang-questions@REDACTED<mailto:erlang-questions@REDACTED>>
Skickat: 27-10-2013 11:13 fm
Ämne: Re: [erlang-questions] more random uniform




I can not replicate this (on R16B01).

> erase(random_seed), random:seed(erlang:now()), random:uniform(3).
1
> erase(random_seed), random:seed(erlang:now()), random:uniform(3).
2
...

?

/Tony


On 27 okt 2013, at 10:45, Bengt Kleberg <bengt.kleberg@REDACTED<mailto:bengt.kleberg@REDACTED>> wrote:

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<http://www.moxier.com/>)
_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED<mailto:erlang-questions@REDACTED>
http://erlang.org/mailman/listinfo/erlang-questions

"Installing applications can lead to corruption over time. Applications gradually write over each other's libraries, partial upgrades occur, user and system errors happen, and minute changes may be unnoticeable and difficult to fix"



_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED<mailto:erlang-questions@REDACTED>
http://erlang.org/mailman/listinfo/erlang-questions

"Installing applications can lead to corruption over time. Applications gradually write over each other's libraries, partial upgrades occur, user and system errors happen, and minute changes may be unnoticeable and difficult to fix"



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20131027/c1489f77/attachment.htm>


More information about the erlang-questions mailing list