Normal distribution

Hi,

I want to write a function that will return a double from a normal distribution, with for instance mean 0.2 and variance 0.1 .
Could anyone help me about this matter please?
In C++11 you can use std::normal_distribution.
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <random>
#include <ctime>

int main()
{
	std::mt19937 generator(std::time(0));
	std::normal_distribution<double> distribution(0.2, 0.1);

	std::cout << distribution(generator) << std::endl;
}
Thank you very much.
This helped a lot.
Topic archived. No new replies allowed.