rand() is much closer to being uniformly distributed than random_d().
random_d() is more likely to return a value above 0 than it is to return a value below 0.
1 2
// Why not 50?
if((rand() % 100) >= 65) a = (-a);
Some type of values are also much more likely than others.
1 2 3 4 5
// Why make the precision random? It makes
// a value with less significant digits more
// likely (e.g. 0.1 is more likely than 0.12)
int n = (rand() % 12) + 1;
if((rand() % 100) >= 95) n = 1;
I am very new to c++. And, I need to create random cordinates. I need to have my coordinate must lie with in -1<x<1 and -1<y<1. Can anyone please help me in solving the issue? I am very beginner in c++. Help be greatly appreciated!
Many thanks,
Muon444
As page 3 looms, I wonder whether Muon444 is any the wiser. :)