<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 03/10/2016 12:59 PM, Heinz Nikolaus
Gies wrote:<br>
</div>
<blockquote
cite="mid:3A896DE7-4144-4AF6-A0FB-6DEFE92D1222@licenser.net"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
This might not be critical any more since seed is deprecated but I
encountered a problem with random today when passing in hand
crafted seeds.
<div class=""><br class="">
</div>
<div class="">The definition of a seed is: <span
style="font-family: Courier, monospace; font-size: 13px;
font-weight: bold; background-color: rgb(255, 255, 255);"
class="">{integer(), integer(), integer()}</span></div>
<div class=""><br class="">
</div>
<div class="">The seed was generated by the method suggested in
random:seed:</div>
<div class="">
<pre style="font-family: Courier, monospace; font-size: 13px; background-color: rgb(238, 238, 255);" class="">{erlang:phash2([node()]),
erlang:monotonic_time(),
erlang:unique_integer()}</pre>
<div class="">This resulted in the seed:</div>
</div>
<div class=""><br class="">
</div>
<div class="">{128631525,-576302453291645741,-576460752303421854}</div>
<div class=""><br class="">
</div>
<div class="">That seed is valid based on the type specification
of seed.</div>
<div class=""><br class="">
</div>
<div class="">Now entered random:uniform_s/2, by specification it
returns a value 1 <= N <= (passed argument) BUT it doesn’t
with this seed:</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">random:uniform_s(10,
{128631525,-576302453291645741,-576460752303421854}).</div>
<div class="">{-1,{23048,-115,-29427}}</div>
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">Yes I know that constructing and passing a seed
like this is evil, please don’t get hung on that, it is not my
code it’s code I am debugging - I fully agree that it probably
should be changed to rand and be done with it, still it looks is
a bug.</div>
<div class=""><br class="">
</div>
<div class="">Cheers,</div>
<div class="">Heinz</div>
<div class=""><br class="">
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
erlang-bugs mailing list
<a class="moz-txt-link-abbreviated" href="mailto:erlang-bugs@erlang.org">erlang-bugs@erlang.org</a>
<a class="moz-txt-link-freetext" href="http://erlang.org/mailman/listinfo/erlang-bugs">http://erlang.org/mailman/listinfo/erlang-bugs</a>
</pre>
</blockquote>
<tt>Since the random module is deprecated in Erlang/OTP 19 and is to
be removed in Erlang/OTP 20 (based on
<a class="moz-txt-link-freetext" href="https://www.youtube.com/watch?v=YlNrWxH56_E">https://www.youtube.com/watch?v=YlNrWxH56_E</a>), I took some time to
modify it in ways that have been pending for a long time at </tt><a class="moz-txt-link-freetext" href="https://github.com/okeuday/quickrand/blob/master/src/random_wh82.erl">https://github.com/okeuday/quickrand/blob/master/src/random_wh82.erl</a>
to force it to use positive integers for seed values (you are never
suppose to allow 0 and in the past abs/1 was used in some places but
not others). The rand usage with exsplus appears to be roughly the
same speed to provide a better period and no real downside, so it
seems hard to argue for using the algorithm in the random module,
unless something else required it. I plan on keeping the
random_wh82 module (code from the random module, modified and put
into the quickrand Erlang application) in case it is needed for
compatibility reasons. So, you could avoid this problem by using
quickrand or you could switch to using the newer rand module.<br>
<br>
Best Regards,<br>
Michael<br>
<br>
</body>
</html>