hello there,
im trying to generate a double precision random number between 0 and
1, but i keep getting 0 only.
class CGUtil
{
public:
static void startRandomNumberGenerator()
{
srand( static_cast<unsigned int>(time( 0 )) );
}
static double randomDouble()
{
return static_cast<double>(rand() / RAND_MAX);
}
};
int main( int argc, char** argv )
{
CGUtil::startRandomNumberGenerator();
for( int i = 0; i < 100; i++ )
std::cout << CGUtil::randomDouble() << std::endl;
return 0;
}
this outputs 0 for the entire loop, ive googled a bit and thats the
technique ppl use to generate pseudo-randoms between 0 and 1. im
casting it to double so theres no truncation (i think).
thanks in advance.