[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua 5.4 random number generator
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 22 Mar 2018 15:57:46 -0300
> You're currently using one modulo operation in the simple case, which on my
> desktop processor (older Core i5) takes longer than a division.
I guess most processors (including i5) use the same instruction to
compute a modulo and a division, so they have exactly the same cost.
> The extra overhead in the common case is one division or slightly less. In
> the worst case the code ends up doing 0 divisions or modulo operations, but
> 2 draws from the
> random generator on average.
I removed that modulo; it is really more expensive than the general case.
(With it, I removed too its corresponding bias.)
> The big issue I had is the short sequence you get when using "random(0, 1)"
> for coin flips. That's beyond a "slight bias."
Sure it is. But I could not find this sequence (see my other message).