[SciPy-dev] random module not working on opteron

Charles Harris charles.harris at sdl.usu.edu
Sun Oct 23 19:29:48 CDT 2005

The mt1997 code on the author's site masks all the operations for 64 bit
compatability, although I suspect this is compiler dependent and shouldn't
matter with gcc. But apparently there was a reason... ;) Also, device
urandom delivers bytes, IIRC, like any other unix file read, so we need to
read 624*sizeof(long) bytes to fill the array.


-----Original Message-----
From: scipy-dev-bounces at scipy.net on behalf of Robert Kern
Sent: Sun 10/23/2005 6:09 PM
To: SciPy Developers List
Subject: Re: [SciPy-dev] random module not working on opteron
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

Scipy-dev mailing list
Scipy-dev at scipy.net

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 4445 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/scipy-dev/attachments/20051023/09624f81/attachment.bin 

More information about the Scipy-dev mailing list