Problems with random numbers
Moderator: Board moderators
Problems with random numbers
Can someone please tell me how to generate random numbers between 0 to 1?
Last edited by lnr on Fri Oct 17, 2008 8:46 pm, edited 1 time in total.
Re: Problems with random numbers
"rand() / static_cast<double>(RAND_MAX)", or "drand48()".
Re: Problems with random numbers
Thanks mf.
But drand48() gets compile time error.
But drand48() gets compile time error.
Last edited by lnr on Fri Oct 17, 2008 8:47 pm, edited 1 time in total.
Re: Problems with random numbers
Well, perhaps you didn't include the right header file (stdlib.h), or your compiler simply doesn't support it.
Re: Problems with random numbers
Without "cstdlib" rand()/static_cast<double>(RAND_MAX) works.
In spite of using "cstdlib" Microsoft Visual C++ 2008 does not support drand48().
In spite of using "cstdlib" Microsoft Visual C++ 2008 does not support drand48().
Code: Select all
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
//cout<<rand()/static_cast<double>(RAND_MAX)<<endl;
cout<<drand48()<<endl;
return 0;
}