Ticket #392 (closed bug: fixed)
Make rand/srand work the same for 32bit and 64bit int
Reported by: | rg | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | library | Version: | trunk |
Severity: | medium | Keywords: | rand srand Math Rand.pir |
Cc: | Language: | ||
Patch status: | applied | Platform: | all |
Description
Currently, the t/library/rand.t test is failing on 64bit platforms, because the new library rand is relying on overflowing with 32bits. See for example this report or the general amd64 smolder listing (sorry can't link).
The attached patch makes the rand function behave the same on 32bit and 64bit platforms.
Disclaimer: I'm not expert on those functions and it could be possible that the 32bit overflow is actually required for a nice distribution.
As an alternative, FreeBSD is using this algorithm (gsl_rng_minstd), which can be calculated without overflowing 31 bits. However, it also has a RAND_MAX of 231 and I don't know if any parrot code relies on rand only having RAND_MAX of 215. Still, if you don't like the patch, I'm offering to implement that algorithm.