diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2011-12-22 17:27:54 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2011-12-22 17:27:54 -0800 |
commit | ba37a43bf36c5f4e787fceb18cb0f4223e98f261 (patch) | |
tree | 8a3941a6809f62641cc82c29af22f0799bcea68d /rand.c | |
parent | 5a00d4815ac646ac275c93203a423b3c7aa1c2a0 (diff) | |
download | txr-ba37a43bf36c5f4e787fceb18cb0f4223e98f261.tar.gz txr-ba37a43bf36c5f4e787fceb18cb0f4223e98f261.tar.bz2 txr-ba37a43bf36c5f4e787fceb18cb0f4223e98f261.zip |
* rand.c (random): Fix for 64 bit fixnums: stick two random numbers
together. Otherwise for fixnum moduli, we get only a 32 bit number no
matter what the modulus is.
Diffstat (limited to 'rand.c')
-rw-r--r-- | rand.c | 4 |
1 files changed, 4 insertions, 0 deletions
@@ -197,7 +197,11 @@ val random(val state, val modulus) cnum m = c_num(modulus); if (m <= 0) goto invalid; +#if SIZEOF_PTR >= 8 + return num(((((cnum) rand32(r) & 0x7FFFFFFF) << 32) | rand32(r)) % m); +#else return num(rand32(r) % m); +#endif } invalid: uw_throwf(numeric_error_s, lit("random: invalid modulus ~s"), |