Generating random number using C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • randomcz
    New Member
    • Oct 2006
    • 5

    #1

    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
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    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.

    Comment

    • randomcz
      New Member
      • Oct 2006
      • 5

      #3
      Thanks, it works.

      Comment

      Working...