Problems with srand(), C++

前端 未结 5 762
被撕碎了的回忆
被撕碎了的回忆 2021-01-28 23:30

I\'m trying to write a program that generates a pseudorandom numbers using a seed. However, I\'m running into problems.

I get this error

39 C:\\Dev-Cpp\         


        
5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-28 23:54

    srand() generates a seed (which is the number used to initialize the random number generator) and must be called once per process. rand() is the function you are looking for.

    If you don't know what seed to pick, use the current time:

    srand(static_cast(time(0))); // include  to use time()
    

提交回复
热议问题