It looks like you're using C++. Have you tried C++11, yet? The newest version of C++ has an extensive <random> library now.
Here is an example of the new std::normal_distribution class included in <random>:
http://www.cplusplus.com/reference/rand ... tribution/
In its constructor, you can set the mean and the standard deviation:
http://www.cplusplus.com/reference/rand ... tirbution/
Note that you will also need to use a generator class--these are also included in <random> to generate the numbers; the std::normal_distribution object will then apply normal distribution to the numbers generated.
I find <random> to be a very useful new addition to the C++ standard library.
From the second link, code that accomplishes what you want with the mean set to 0.0 and the standard deviation set to 1.0:
Code:
// normal_distribution example
#include <iostream>
#include <chrono>
#include <random>
int main()
{
// construct a trivial random generator engine from a time-based seed:
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::default_random_engine generator (seed);
std::normal_distribution<double> distribution (0.0,1.0);
std::cout << "some Normal-distributed(0.0,1.0) results:" << std::endl;
for (int i=0; i<10; ++i)
std::cout << distribution(generator) << std::endl;
return 0;
}
It seeds the generator, of
std::default_random_engine class with a seed obtained from the current time, to produce pseudo-random numbers. Then a
std::normal_distribution object, specialized with numbers of real type
double, is created with the mean set to 0.0 and the standard deviation set to 1.0. It then generates some results.
On the
first page, the main page for
std::normal_distribution, it shows how, with the mean set to 5.0 and the standard deviation set to 2.0, pseudo-random numbers are generated in a normal distribution, in the output:
Code:
normal_distribution (5.0,2.0):
0-1: *
1-2: ****
2-3: *********
3-4: ***************
4-5: ******************
5-6: *******************
6-7: ***************
7-8: ********
8-9: ****
9-10: *
I hope this is helpful to you.
_________________
"You have a responsibility to consider all sides of a problem and a responsibility to make a judgment and a responsibility to care for all involved." --Ian Danskin