[lug] Platform independent randomness

Ed Hill ed at eh3.com
Thu Nov 29 22:59:47 MST 2001


Ken Weinert wrote:

> 	Does anyone have any pointers to an algorithm for
> rand()/srand() that is platform independent? In this case the 3
> platforms of concern are sun/solaris, sun/x86, linux/x86.
> 
> 	The requirements are that given a particular seed, all 3
> platforms will generate the same sequence of (pseudo) random numbers.
> This isn't a highly secure application, so this doesn't have to be the
> most robust algorithm, just repeatable on the 3 platforms above.
> 



Hi Ken,

Heres part of a code that I wrote some years ago that does exactly
what you want.  You'll have to strip out the Tracer() junk (easily
done) and some other stuff but it should be trivial to convert it
from C++ into a C code snippet (very portable).

I'll be happy to help if you need it...

Ed

ps - As a bonus the r250 algo has a very long period which made it 

      good for Monte Carlo methods...  whatever...  ;-)


-- 
Edward H. Hill III, PhD
Post-Doctoral Researcher    |  Emails:   <ed at eh3.com>, <ehill at mines.edu>
Division of ESE             |  URL:      http://www.eh3.com
Colorado School of Mines    |  Phone:    303-273-3483
Golden, CO  80401           |  Fax:      303-273-3311
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CMRRGenerator_r250.C
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20011129/ae1b88d6/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CMRRGenerator_r250.h
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20011129/ae1b88d6/attachment.h>


More information about the LUG mailing list