I wrote this for an encryption project Im working on. Thought you guys might like to use it if you have need of a cryptographic strength random number generator.
I wrote this for an encryption project Im working on. Thought you guys might like to use it if you have need of a cryptographic strength random number generator.
I'm pretty tired right now, but if you could explain how it works, it would help me a lot.
From what I see, it looks like it creates a huge array of prime numbers < 65536, and a huge array of all 1's
Then GetByte() does a calculation and saves it in the State array, and then assigns the result of another calculation to the pByte parameter.
GetString() just calls GetByte() for each element of the string parameter.
BTW, won't the Prime member array only have 6542 numbers in it and the rest would just be garbage left in memory? At least according to this site: http://primes.utm.edu/lists/small/10000.txt the first 6542 prime numbers go up to 65521.
There's 2 functions to call.
GetByte() obviously returns a random byte.
GetString(BYTE* , DWORD) returns a string of length DWORD.
Yes it just calls GetByte repeatedly.
As for the theory behind how it generates the random numbers, maybe some other time
BTW, check out www.anthonyqbachler.com for a much larger list of primes, and take another look at the code, it doesnt find the primes up to 65536, it finds 65536 primes.
Last edited by abachler; 09-02-2008 at 11:18 PM.
It must take a long time to find all those prime numbers. Wouldn't it be better to store all those primes in a file and then read them in rather than re-calculating them all the time?
It takes under 400ms, once, when the class is created. Using a file would take a similar amount of time, require pregeneration by another program, and wouldn't be adjustable as easily.
Last edited by abachler; 09-03-2008 at 08:38 AM.