Hey guys,
I have to create a program that, at first, generates a real number based on normal probability with given mean and standard deviation. I have found such ways to do this in Matlab and Mathematica software but I need to create my own program because the program will need to do more than just this. I am stuck at this topic. All I have found in forums is this code:
Normal Z;
for(i=0;i<100;i++)
cout << Z.Next << "\n";
This is supposed to make random integers based on normal probability but I need real numbers not integers.
First of all...
What libraries do I need?
Is "Normal" even a c++ function?
Any thoughts would be greatly appreciated!
I do believe that real numbers are integers. Although definitions of integers and natural numbers vary from many different places.
What libraries do I need?
#include <cstdlib>
look into rand() and srand().
EDIT: wikipedia says so:
The integers (from the Latin integer, literally "untouched", hence "whole": the word entire comes from the same origin, but via French[1]) are formed by the natural numbers including 0 (0, 1, 2, 3, ...) together with the negatives of the non-zero natural numbers (−1, −2, −3, ...). Viewed as a subset of the real numbers
@king214
you are correct, integers are real numbers but real numbers also include all numbers opposite imaginary/complex numbers. The numbers I need output will have to be decimal numbers and then i will have the program round the numbers. The <cstdlib> is the library I thought I would need. I have looked into rand() and srand() but they do not deal with normal probability. Thank you for your help.
@jsmith
still looking at the website you provided but not sure If I understand it completely yet. Can I input my own values for mu and sigma where the 0 and 1 are?
It is probably worth noting that the boost::normal_distribution is not a generator, it is just a transform. You have to connect it to a generator to make it work, you can either do this manually or with a boost::variate_generator.