OK, I've finished a class for a random number stream generator
Features are:
- You may instantiate multiple number streams
- Repeatability, based on 32bit int number seeds
- the PRNG is a Mersenne Twist algorithm, yielding a good distribution
- Various random functions:
-- rand() returns a 32bit int between 0 and 0xffffffff
-- normalized() returns a float between 0.0 and 1.0
-- even() returns bool (either true or false)
-- deviated returns, well, potentially ANY number, with the output being distributed in a bell curve based on a median and standard deviation that you supply the function.
If desired, I will implement state saving / loading features, though I don't know if this is necessary.
I don't foresee speed being an issue; on my machine (an Athlon XP 1700+) I can easily generate a few million deviated random numbers (they take far longer than the other varieties) in a second or two.
If people are OK with this, I'd like to incorporate it into ClanLib, as I believe such a system is rather useful. I'll have a patch ready for approval in a day or two.
...Chambers
PS In the archive, you will find 3 files: a header file, an implementation file and a test file. The test takes some user input, and validates the PRNG distributing results correctly.
Bookmarks