Bug in random seed (definition?) and random:uniform_s/2
Heinz Nikolaus Gies <[email protected]> Thu, 10 Mar 2016 15:59:32 -0500
| Newsgroups | gmane.comp.lang.erlang.bugs |
|---|---|
| Message-ID | <[email protected]> |
--===============0491843487535383287==
Content-Type: multipart/signed; boundary="Apple-Mail=_E5463E31-D7EB-48BB-8877-179208353F63"; protocol="application/pgp-signature"; micalg=pgp-sha512
--Apple-Mail=_E5463E31-D7EB-48BB-8877-179208353F63
Content-Type: multipart/alternative;
boundary="Apple-Mail=_7C2B1584-16A1-4F10-AC37-5748F8CF4811"
--Apple-Mail=_7C2B1584-16A1-4F10-AC37-5748F8CF4811
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=utf-8
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.
The definition of a seed is: {integer(), integer(), integer()}
The seed was generated by the method suggested in random:seed:
{erlang:phash2([node()]),
erlang:monotonic_time(),
erlang:unique_integer()}
This resulted in the seed:
{128631525,-576302453291645741,-576460752303421854}
That seed is valid based on the type specification of seed.
Now entered random:uniform_s/2, by specification it returns a value 1 <=3D=
N <=3D (passed argument) BUT it doesn=E2=80=99t with this seed:
random:uniform_s(10, =
{128631525,-576302453291645741,-576460752303421854}).
{-1,{23048,-115,-29427}}
Yes I know that constructing and passing a seed like this is evil, =
please don=E2=80=99t get hung on that, it is not my code it=E2=80=99s =
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.
Cheers,
Heinz
--Apple-Mail=_7C2B1584-16A1-4F10-AC37-5748F8CF4811
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
charset=utf-8
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html =
charset=3Dutf-8"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" =
class=3D"">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=3D""><br class=3D""></div><div class=3D"">The =
definition of a seed is: <span style=3D"font-family: Courier, =
monospace; font-size: 13px; font-weight: bold; background-color: =
rgb(255, 255, 255);" class=3D"">{integer(), integer(), =
integer()}</span></div><div class=3D""><br class=3D""></div><div =
class=3D"">The seed was generated by the method suggested in =
random:seed:</div><div class=3D""><pre style=3D"font-family: Courier, =
monospace; font-size: 13px; background-color: rgb(238, 238, 255);" =
class=3D"">{erlang:phash2([node()]),
erlang:monotonic_time(),
erlang:unique_integer()}</pre><div class=3D"">This resulted in the =
seed:</div></div><div class=3D""><br class=3D""></div><div =
class=3D"">{128631525,-576302453291645741,-576460752303421854}</div><div =
class=3D""><br class=3D""></div><div class=3D"">That seed is valid based =
on the type specification of seed.</div><div class=3D""><br =
class=3D""></div><div class=3D"">Now entered random:uniform_s/2, by =
specification it returns a value 1 <=3D N <=3D (passed argument) =
BUT it doesn=E2=80=99t with this seed:</div><div class=3D""><br =
class=3D""></div><div class=3D""><div class=3D"">random:uniform_s(10, =
{128631525,-576302453291645741,-576460752303421854}).</div><div =
class=3D"">{-1,{23048,-115,-29427}}</div></div><div class=3D""><br =
class=3D""></div><div class=3D""><br class=3D""></div><div class=3D"">Yes =
I know that constructing and passing a seed like this is evil, =
please don=E2=80=99t get hung on that, it is not my code it=E2=80=99=
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=3D""><br class=3D""></div><div class=3D"">Cheers,</div><div =
class=3D"">Heinz</div><div class=3D""><br class=3D""></div></body></html>=
--Apple-Mail=_7C2B1584-16A1-4F10-AC37-5748F8CF4811--
--Apple-Mail=_E5463E31-D7EB-48BB-8877-179208353F63
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename=signature.asc
Content-Type: application/pgp-signature;
name=signature.asc
Content-Description: Message signed with OpenPGP using GPGMail
-----BEGIN PGP SIGNATURE-----
iQIcBAEBCgAGBQJW4eA1AAoJEKM5c9dFK2+YYKAQAJRVXsDzQRsZdQOWynnztfaD
2tD8jgZvKhE2EFZsi9kZS4488SrizmPHnrVMBZV8Ukxdv8cligCoeC3Go9wjfXI6
M5CnomJqb+uNvJ2V+o8V16wXQO/PIWR3c/L4rFYkIDo+7vwlVluxocB5QqkLJVfl
6k2utqWhYRm/3/V7u50F1Y/i5ivQH98e9RNnXWzgo+MV//cnFx/a01dDwcpzTzKp
h9CctUzWnomn/prbMcrXWN/eWNngnRrVZGYRn6uTwRN2E+vRfDKfb2LJCO4xpUzY
L1z1nUC2x5Z1OhNFKBg4Ee33nyE9ju+cbizbrMQZa00nwQ7ifwAP3jhWT80yITjt
YjNmkSkAUW/6fMv5NWlnlCJsXSObi5UgUSITXn6HwRB6/lJFhp0VWwlF3U9MeJcj
Q+MRUa/0u+uhG8my7v7/o3TatyFj99SdTuQpSuG9gMGH20EVJoEiKMLzQ+nvJpsG
+vJqmiR3Q/rPk+hP7IOtsE03+0E0VL2tFWwO0ObuTTAlGR7RTclGm9PrwgMaDEZR
iRC5sGVN7XH+4Faoholmu4/OqI6M/1vSLXTUHvFker1J2Y0pY4sRx2N2oXlme86a
1hb7J/fSSvyNYX/UdIdR/IZdMky0D63PSEtJ7GyNcLiMLlQ8zXjqFWnU8iAe7vD8
YkN3NVXz/HmjDYKY7Dh/
=FBWM
-----END PGP SIGNATURE-----
--Apple-Mail=_E5463E31-D7EB-48BB-8877-179208353F63--
--===============0491843487535383287==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
erlang-bugs mailing list
[email protected]
http://erlang.org/mailman/listinfo/erlang-bugs
--===============0491843487535383287==--