I am looking for a C++ library which has a random number generator for a normal distribution which works thusly:
I give it two parameters, a mean and a standard deviation
It returns a random number to me, with probabilities according to the normal distribution (IE, 50% chance that the number returned is lower than the mean, 34.13% chance the number is less than the mean-standard deviation). The random number can be based on anything "random" I can pass into it (like system time or something).
Is there a library out there which has a function like this?
Edit: I guess I would want the input and output to be doubles. 3 or 4 digits precision should be plenty.
Statistics Libarary for C++
I am looking for a C++ library which has a random number generator for a normal distribution which works thusly:
I give it two parameters, a mean and a standard deviation
It returns a random number to me, with probabilities according to the normal distribution (IE, 50% chance that the number returned is lower than the mean, 34.13% chance the number is less than the mean-standard deviation). The random number can be based on anything "random" I can pass into it (like system time or something).
Is there a library out there which has a function like this?
Edit: I guess I would want the input and output to be doubles. 3 or 4 digits precision should be plenty.
I dont know of any library but it would be easy to do it yourself.
Just map a random float (-1.0, 1.0) onto (-4*SD,4*SD) and use a table to find the cumulative percentages every 0.1 or something. That sounded terrible, If you havn't found one I will try and whip one up.
So the answer is I dont know one, but I think it would be easy to do yourself.
Oh, BOOST has one.
See the Box-Muller transform, as well as the Ziggurat method (linked from that page).
[TheUnbeliever]
I haven't used it, but I know that boost contains a random distribution. It might be worth looking into.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement