Reputation: 93
I want to get random uniform number using drand48 in .cu format files why I always give me 3.90799e-14 this value
my code is in ran_uniform_test.cu
#include <iostream>
int main( int argc, char** argv)
{
std::cout<<drand48()<<"\n";
return 0;
}
Upvotes: 0
Views: 757
Reputation: 64068
You should call srand48
(or seed48
, or lcong48
) prior to using drand48
:
The srand48(), seed48() and lcong48() are initialisation entry points, one of which should be invoked before either drand48(), lrand48() or mrand48() is called. (Although it is not recommended practice, constant default initialiser values will be supplied automatically if drand48(), lrand48() or mrand48() is called without a prior call to an initialisation entry point.) The erand48(), nrand48() and jrand48() functions do not require an initialisation entry point to be called first.
Used like so:
#include <iostream>
#include <ctime>
#include <cstdlib>
int main(int argc, char *argv[])
{
// A common random seed strategy is to use the current time
srand48(time(NULL));
std::cout << drand48() << std::endl;
std::cout << drand48() << std::endl;
std::cout << drand48() << std::endl;
std::cout << drand48() << std::endl;
return 0;
}
Upvotes: 2