Ticket #392 (closed bug: fixed)

Opened 13 years ago

Last modified 13 years ago

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.

Attachments

rand.patch Download (0.8 KB) - added by rg 13 years ago.

Change History

Changed 13 years ago by rg

Changed 13 years ago by coke

Please TT #189

Changed 13 years ago by fperrad

  • status changed from new to closed
  • resolution set to fixed
  • patch set to applied

Patch applied in r37087.

Other algorithm like gsl_rng_minstd could be implemented in other namespace like [ 'Math'; 'Random'; 'MINSTD'] with the same interface (rand, srand, RAND_MAX).

Diversity is a good thing.

Note: See TracTickets for help on using tickets.