Creating random coordinates

Pages: 12
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;
Last edited on
@Peter87
> // Why not 50?
If it was exactly 50::50, more negative numbers would be generated than positive numbers.

Edit : I tested that quite carefully.
Last edited on
@closed account 5a8Ym39o6 (310)

I seriously think you are trolling, you continue to push your solution just to provoke comment.
@TheIdeasMan
And explain why do you need to pursue me like that?
closed account (48T7M4Gy)
Hello everyone,

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. :)
Topic archived. No new replies allowed.
Pages: 12