468,741 Members | 2,032 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,741 developers. It's quick & easy.

Generating random number using C++

hi,

i need help with generating random numbers;

The task is to generate hundreds of random vectors, like
1,3,5,6,7
2,4,5,4,8
...

I used the current time as the random seed, but it turns out
that every vector to be the same. I guess the problem arise
because the precision of time function limits to 1 second,
and in a very short time interval, the random seed is exactly
the same and thus all the vectors the same.

Does anybody know some better seed for this problem? or
any other random number generating functions?

Thanks,
Z
Oct 30 '06 #1
2 2373
Ganon11
3,652 Expert 2GB
Are you calling the randomize function (a.k.a. resetting the seed) more than once? I once got a similar problem, getting the same 'random' numbers over and over again, because I reset the seed multiple times. Try setting the seed once in the very beginning of your main.
Oct 30 '06 #2
Thanks, it works.
Oct 31 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by eric.gagnon | last post: by
16 posts views Thread by Leon | last post: by
6 posts views Thread by Intiha | last post: by
2 posts views Thread by Simon Wittber | last post: by
26 posts views Thread by bilgekhan | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.