What's wrong with my random number generator?

前端 未结 3 1673
借酒劲吻你
借酒劲吻你 2021-01-17 04:14

I\'m just diving into some C++ and I decided to make a random number generator (how random the number is, it really doesn\'t matter). Most of the code is copied off then net

3条回答
  •  野的像风
    2021-01-17 04:45

    The problem is that you use srand everytime. CPU is so fast that it will execute all this code in a single second, so you get the same seed each time.

    Move srand out of the loop, call it only once.

提交回复
热议问题