Does stdlib's rand() always give the same sequence?

前端 未结 6 1873
甜味超标
甜味超标 2020-12-07 02:24

I quite like being able to generate the same set of pseudo-random data repeatedly, especially with tweaking experimental code. Through observation I would say that ran

6条回答
  •  被撕碎了的回忆
    2020-12-07 02:31

    If you need to use the exact same set of pseudo-random numbers for experimental purposes, one thing you could do is to use srand to generate a long sequence of random numbers and write them to a file/database. Then, write a portable "random number generator" function that returns values sequentially from that file. That way, you can be assured that you are using the same input data regardless of the platform, srand implementation, or seed value.

提交回复
热议问题