<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">No it was not necessary, just making sure it was fresh every time.<div><br></div><div>Any particular reason to keep the third argument to zero in the random:seed/3 call ?</div><div>This will, as you point out, generate an initial sequence of small random:uniform numbers.</div><div>Looking at random.erl the calculation is (modified in this context):</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>(((X+1)*171) rem 30269) / 30269 +</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>(((Y+1)*172) rem 30307) / 30307 + </div><div><span class="Apple-tab-span" style="white-space:pre"> </span>(((0+1)*170) rem 30323) / 30323</div><div><br></div><div>Keeping the X and Y small enough (less than 176 ) we can rewrite this as:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>R = ((X+1)*171) / 30269 + ((Y+1)*172) / 30307 + 170 / 30323</div><div><br></div><div>The value of this expression will be small given small values on X and Y, and the expression</div><div>trunc(R*3) will be zero for X+Y < 56 (roughly)</div><div><br></div><div>In other words use larger numbers, and use them all, when seeding the random number generator.</div><div><br></div><div>/Tony</div><div><br></div><div><div><br><div><div>On 27 okt 2013, at 11:48, Bengt Kleberg <<a href="mailto:bengt.kleberg@ericsson.com">bengt.kleberg@ericsson.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<div style="word-wrap:break-word">
<pre style="word-wrap: break-word; font-size: 10pt; font-family: Tahoma; ">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
(<a href="http://www.moxier.com">http://www.moxier.com</a>)
----- Ursprungligt meddelande -----
Från: Bengt Kleberg <<a href="mailto:bengt.kleberg@ericsson.com">bengt.kleberg@ericsson.com</a>>
Till: null
Kopia: "<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>" <<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>>
Skickat: 27-10-2013 11:33 fm
Ämne: Re: [erlang-questions] more random uniform
</pre>
<div>
<pre style="word-wrap: break-word; font-size: 10pt; font-family: Tahoma; ">Thank you.
I have 15B.
Is the erase/1 necessary? I am using new processes each time.
Bengt
Sent from Moxier Mail
(<a href="http://www.moxier.com">http://www.moxier.com</a>)
----- Ursprungligt meddelande -----
Från: Tony Rogvall <<a href="mailto:tony@rogvall.se">tony@rogvall.se</a>>
Till: Bengt Kleberg <<a href="mailto:bengt.kleberg@ericsson.com">bengt.kleberg@ericsson.com</a>>
Kopia: "<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>" <<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>>
Skickat: 27-10-2013 11:13 fm
Ämne: Re: [erlang-questions] more random uniform
</pre>
<div>I can not replicate this (on R16B01).
<div><br>
</div>
<div>
<div>> erase(random_seed), random:seed(erlang:now()), random:uniform(3).</div>
<div>1</div>
<div>
<div>> erase(random_seed), random:seed(erlang:now()), random:uniform(3).</div>
<div>2</div>
</div>
<div>...</div>
<div><br>
</div>
<div>?</div>
<div><br>
</div>
<div>/Tony</div>
<div><br>
</div>
<div><br>
<div>
<div>
<div>On 27 okt 2013, at 10:45, Bengt Kleberg <<a href="mailto:bengt.kleberg@ericsson.com">bengt.kleberg@ericsson.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">Greetings,<br>
<br>
When doing random:uniform/1 for small values, ie 3, the result is 1 the first time. Changing the seed does not help.<br>
What am I missing?<br>
<br>
<br>
Bengt<br>
<br>
Sent from Moxier Mail<br>
(<a href="http://www.moxier.com/">http://www.moxier.com</a>)<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote>
</div>
<br>
<div><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px; ">
<div><span class="Apple-style-span" style="color:rgb(51,51,51); font-family:Geneva,Arial,Helvetica,sans-serif; font-size:12px">"Installing applications can lead to corruption over time. </span><span class="Apple-style-span" style="color:rgb(51,51,51); font-family:Geneva,Arial,Helvetica,sans-serif; font-size:12px">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"</span></div>
<div><span class="Apple-style-span" style="color:rgb(51,51,51); font-family:Geneva,Arial,Helvetica,sans-serif; font-size:12px"><br>
</span></div>
</span><br class="Apple-interchange-newline">
</div>
<br>
</div>
</div>
</div>
</div>
</div>
</div>
_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>http://erlang.org/mailman/listinfo/erlang-questions<br></blockquote></div><br><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; ">"Installing applications can lead to corruption over time. </span><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; ">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"</span></div><div><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; "><br></span></div></span><br class="Apple-interchange-newline">
</div>
<br></div></div></body></html>