[SciPy-dev] random module not working on opteron

Robert Kern rkern at ucsd.edu
Sun Oct 23 19:09:42 CDT 2005

Arnd Baecker wrote:
> On Sun, 23 Oct 2005, Robert Kern wrote:
>>Arnd Baecker wrote:
> [...]
>>>Can anyone with a 64 Bit machine confirm this behaviour?
>>>What could one do to hunt this one down?
>>I would first check if the RandomKit functions work correctly from C.
>>See the files randomkit.[ch] ; the functions should be self-explanatory.
>>It's entirely possible that they're not 64-bit safe; I never had the
>>opportunity to check.
> Ok, referring to a famous scene of the Life of Brian:
> after more than 5 years of not speaking C at all
> you are stepping on my feet and I speak C again - a miracle!
> (What a pleasure, no need to pay attention to white space,
> I love all those variable declarations and ";"... Thank you ;-).
> Now to the facts:
> - the code below works fine on my PIV
> - on the opteron it gives problems and hangs:
> Value: 1791095845l max=4294967295l
> Value: 0.997185
> Now with random seed:
> Value: 920722385l max=4294967295l
>    Value: 915381373.352906                    # <----- not ok! (rk_double)
> Now test the distributions:
> rk_uniform: 566004099.864036                  # <----- not ok!
> rk_normal:                                    # (hangs)
> The problem is caused by calling rk_random_seed
> (Commenting this one out, everything seems fine).
> I am not sure what is going on in that routine
> (and have to leave investigating this at the moment ...)
> Maybe you can have a look at that routine
> and spot anything which might be problematic?
> (either 64 Bit, or the clock stuff???)

I think the issue is that the state is an array of 624 unsigned longs.
rk_seed() essentially just does 32-bit arithmetic and so fills those
longs with numbers up to 2**32-1. rk_randomseed(), however, takes raw
bits from /dev/urandom and drops them into the array. I believe that the
algorithm is expecting 32-bit integers.

I've applied a mask to the state after it gets seeded by /dev/urandom.
Please checkout the latest version of randomkit.c from SVN and give it a
try. We may need to make this more robust later, but for now it might work.

Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

More information about the Scipy-dev mailing list