rand() generating the same number – even with srand(time(NULL)) in my main!

后端 未结 7 657
执念已碎
执念已碎 2020-11-28 15:49

So, I\'m trying to create a random vector (think geometry, not an expandable array), and every time I call my random vector function I get the same x value, though y and z a

7条回答
  •  悲哀的现实
    2020-11-28 16:13

    Not directly related to the code in this question, but I had same issue with using srand ((unsigned)time(NULL)) and still having same sequence of values being returned from following calls to rand().

    It turned out that srand needs to called on each thread you are using it on separately. I had a loading thread that was generating random content (that wasn't random cuz of the seed issue). I had just using srand in the main thread and not the loading thread. So added another srand ((unsigned)time(NULL)) to start of loading thread fixed this issue.

提交回复
热议问题