rand() returns same values when called within a single function

前端 未结 5 1952
清酒与你
清酒与你 2020-11-22 15:25

I\'m a C++ newbie and I\'m stumped on this. I need to call this function in my main function three times but each time it gives me the same result, i.e. pull_1, pull_2, pul

5条回答
  •  独厮守ぢ
    2020-11-22 16:15

    You shouldn't call srand() before each call to rand(). Call it once – somewhere at the start of your program.

    The problem is you restart the random generator so it starts to produce the very same pseudorandom sequence from the very same point.

提交回复
热议问题