rand with seed does not return random if function looped

前端 未结 5 943
滥情空心
滥情空心 2020-12-17 21:19

I wrote this C code below, when I loop, it returns a random number. How can I achieve the 5 different random values if myrand() is executed?

#include 

        
5条回答
  •  半阙折子戏
    2020-12-17 21:47

    The point of seed() is to start the sequence of random numbers with a known value,
    you will then always get the same sequence of numbers given the same seed.

    This is why you have seed(), it both allows you to generate the same sequence for testing, or given a random seed (typically the time) you get a different sequence each time

提交回复
热议问题