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

前端 未结 5 1951
清酒与你
清酒与你 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:20

    The time(0) function may not have 'ticked' between function calls. So you are seeding the random number generator with the same value each time, leading to identical values for rand()

提交回复
热议问题