By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,180 Members | 1,140 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,180 IT Pros & Developers. It's quick & easy.

Generating random number using C++

P: 5
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
Share this Question
Share on Google+
2 Replies


Ganon11
Expert 2.5K+
P: 3,652
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

P: 5
Thanks, it works.
Oct 31 '06 #3

Post your reply

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