[erlang-bugs] Bug in module random (stdlib-1.16.5, R13B04)

Raimo Niskanen raimo+erlang-bugs@REDACTED
Tue Jun 15 09:30:41 CEST 2010


On Mon, Jun 14, 2010 at 11:15:48PM +0200, Florian Schintke wrote:
> [Raimo Niskanen]
> > Thank you for reporting this problem. Your suggested fix to replace
> > 0 with 1 in the seed also seems as the least bad workaround.
> > 
> > I am amazed nobody reported this before.
> > 
> > It will be fixed or at least documented in earliest feasible release
> > (unfortunately not R14A).
> 
> To also fix the additional problem that a 0 could be generated by the
> modulo operation when numbers for a seed are larger than the prime
> numbers used in the algorithm, one should do first the calculation as
> currently done and then check whether the result is zero.  So my
> proposal for a new random:seed/3 would be something similar to this:
> 
> seed(A1, A2, A3) ->
>     case abs(A1) rem 30269 of 0 -> T1 = 1; T1 -> T1 end,
>     case abs(A2) rem 30307 of 0 -> T2 = 1; T2 -> T2 end,
>     case abs(A3) rem 30323 of 0 -> T3 = 1; T3 -> T3 end,
>     put(random_seed, {T1, T2, T3}).

Great! Well spotted again. Something like that...

> 
> 
> Florian
> -- 
> Florian Schintke <schintke@REDACTED>, http://www.zib.de/schintke/
> 
> ________________________________________________________________
> erlang-bugs (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-bugs-unsubscribe@REDACTED

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB


More information about the erlang-bugs mailing list