471,601 Members | 1,665 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,601 software developers and data experts.

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 2494
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 MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.