I am having trouble generating a normal distributed number using the Box-Muller Method in Numerical Recipes. I tried declaring in my main section a norm_dev as a Normaldev_BM type. Then printing, but no luck! Please help
Thank you! That worked like a charm, but now I seem to only be generating the same number over and over again. How do I go about changing this? So every time I print norm_dev.dev() i want a new normal deviate.
I think Doub is a typedef for double. I don't know why Numerical Recipes does this though.
Every time I run my code I get the same 10 numbers.
I used this in my code:
1 2 3 4 5 6 7 8 9 10 11 12
int main()
{
//Line below creates a new uniform number between 0 and 1 when I call ran.doub()
Ran ran(time(0));
Normaldev_BM norm_dev(0,0.447,ran.doub());
for(int i=0;i<10;i++)
{
cout << norm_dev.dev() << endl;;
}
system("pause");
return 0;
}
I want to be able to generate 10 new numbers each time I run the code.
The third parameter for your Normaldev_BM constructor takes a value of type unsigned long long. Perhaps you should should feed it a value of that type instead of a double between 0 and 1?
1 2 3 4 5 6 7 8
int main()
{
Ran ran(std::time(0)) ;
Normaldev_BM norm_dev(0.0, 0.447, ran.int64()) ;
for ( unsigned i=0; i<10; ++i )
std::cout << norm_dev.dev() << '\n' ;
}