|
From: Alfred P. R. <al...@ya...> - 2005-01-25 21:09:06
|
Hi Erika, There's lots of random number generators in C and C++. A good place to start is Google for 'diehard random number generator C++'. It's a good start as any RNG that can pass the Diehard tests is a good RNG. See Description of the Rand Function in Excel 2003 and Diehard Battery of Tests of Randomness. On the second link, download the zip file for Windows Software (732KB), http://www.cs.hku.hk/~diehard/cdrom/diehard.zip. After extracting, open make.txt, which has numerous RNG examples. I know this as I've been working recently on analyzing the capability of the C++ library rand() call. It totally sucks! In the alternative, I'm using something like the following, which is however, slow, and I'm looking for a faster version myself that doesn't use floating point! #define TWORAISED16 65536 unsigned int secure_random ( void ) { /* This method implements a more secure random number generator using the Wichman and Hill procedure. An unsigned integer is returned. Alfred P. Reaud, 05/01/05 12:04 VERIFIED: 05/01/05 12:48 */ int ix = 0; int iy = 0; int iz = 0; double result = 0; double rand_f = 0; double i_part = 0; // Create 3 random numbers. ix = (171 * rand()) % 30269; iy = (172 * rand()) % 30307; iz = (170 * rand()) % 30323; // Sum them as a double. result = ((double)ix / 30269.0) + ((double)iy / 30307.0) + ((double)iz / 30323.0); // Make a random number that will be 16 bits wide. rand_f = modf(result, &i_part) * TWORAISED16; result = modf(rand_f, &i_part); return ((unsigned int)i_part) % TWORAISED16; } Erika Brattich <eri...@st...> wrote: Hi everybody, does anybody where to find a random generator for C++(the function rand() in the library stdlib is not what I need)? I'm a beginner in the field of programming and I try to read some programs and to correct them in order to learn... Could you suggest me some sites where I can find good, but not tooo difficult, programs working on Dev C++? Thank you very much!!! Alfred P. Reaud |