Skybuck Flying said:
What is the best replacement for nrand48() for Visual C/C++ 6.0 ?
Dangerously near to off-topic;-) If RAND_MAX is 2147483647 (2^31 - 1)
on your system you can probably replace nrand48() by the standard C
function rand() without any changes (unless the algorithms used in the
program rely also on some other properties of the nrand48() function,
see
http://www.opengroup.org/onlinepubs/009695399/functions/drand48.html
Otherwise you have to look out for some other function that returns
uniformely distributed pseudo-random numbers in the interval [0,2^31),
I guess someone in a MS-programming group will know what to use.
Yes, I believe the program relies on nrand48 special properties...
You mean that it uses a linear congruential algorithm and 48-bit
integer arithmetic, so it is not just used as a normal generator
of 32-bit pseudo-random numbers but depends on the exact sequence
the numbers are produced? In that case you may have to write your
own version, the algorithm is described on the page with the URL
I posted.
I am not sure what the program depends on. The safest bet would be to have
an nrand48() function on windows which returns exactly the same numbers as
the nrand48() function on unix.
I see a number of possibilities:
1. Find the source code for nrand48() and have it compile/work on windows.
This probably requires a lot of other source for rand48() etc...
2. Use another random number generator like "Mersenne Twister"... maybe it
can also produce:
"return non-negative, long integers, uniformly distributed over the interval
[0,2^31]."
The best thing would be if it were the same numbers but that's probably
unlikely.
Maybe the Mersenne Twister is even a better random number generator than
nrand48
3. Write an nrand48() implementation from scratch
<- I rather not do that
since I don't know anything about random number generators or 48 bit
arithmetic, and I suck at statistics =D
I also tried linking the library 'libgw32c.a' in visual c, but that did not
work. I think the library is not ment for visual c... maybe it's ment for
gnu c compilers.
The source code of the library 'libgw32c.a' is also available so I might
succeed in extracting the necessary code for the nrand48() functions and any
other needed function and then putting that in a seperate file
I would still have to find a way to make sure that it procedures the same
numbers as on unix... I should least have some indication that it s working
correctly.
Maybe I am taking it a little bit to extremes... since I know that a c
compiler is just an implementation of the c language... and each c compiler
can have errors or produce code that proceduces different results. So in
other words a unix c program might produce other results than the same c
program on windows.
Bye,
Skybuck.