views:

217

answers:

4

I'd like to generate an array of Random numbers with defined Min, Max, Mean and Stdev with given number of elements and error level. Is there such a library in C, C++, PHP or Python to do so? Please kindly advise. Thanks!

+3  A: 

http://www.boost.org/doc/libs/1_42_0/libs/random/random-distributions.html

Andreas Brinck
+1 thanks Andreas!
Viet
+4  A: 

The Boost C++ random number library may do some of what you want, certainly you can with some distributions select the modal value of the distribution. That's all I've needed in my own code, so I've never investigated further. The library doesn't generate arrays - you would typically use a C++ std::vector to contain the results of random number generation.

anon
+1 thanks! Sounds good to me.
Viet
@Vliet If you are interested in generating random data (not just numbers) you might want to take a look at my FOSS project at http://code.google.com/p/csvtest, though it doesn't do what your question asks about.
anon
+1 Great! Thanks for sharing!
Viet
+4  A: 

If you want to use python, then I suggest that you use numpy.

http://docs.scipy.org/doc/numpy/reference/routines.random.html

You can probably find many distributions that fit your needs, but maybe you can sample from a beta distribution and rescale the values to fit your needs. Your code will end up looking like this

a1, a2 = ....
temp_array = numpy.random.beta(a1, a2, array_size)
answer = temp_array*(max_value-min_value) + min_value

If you choose this aproach then you need to do a bit of work to find formulas for a1 and a2.

niels
+1 Thanks. Looks promising.
Viet