Change seed for every generated random number

2019-08-14 14:18发布

Suppose you generate random numbers using the seed as the time elapsed in seconds since january 1970 as in microsoft library. But you change the seed after every single random number generated. Will that give a truly random result. Why or why not?

Edit I just had one more part to the question. What if I get the seed to be non-deterministic. For a small example, take that the seed is generated by an already existing TRNG(true random number generator). In other words, if I can make the seed non deterministic somehow, will I be able to generate a random sequence i.e. a non - deterministic sequence. Why or why not?

标签: random
2条回答
爷的心禁止访问
2楼-- · 2019-08-14 14:49

True randomness does not require a seed. Seeding is only applicable to PRNGs, which are 100% deterministic, and not truly random.

So no, using a PRNG in any form will not yield true randomness.

查看更多
Animai°情兽
3楼-- · 2019-08-14 15:09

Essentially, your technique simply shifts the "randomness" to when you call the random() function: if you call the function at deterministic times (e.g. once per second) the results will be deterministic. If you call the function at random times, the results will be random.

More accurately, it depends on the what value you call the seed() function with. If you call seed() with deterministic values, the results of the subsequent call to random() will be deterministic.

update (by request):

A software random generator is COMPLETELY deterministic; the sequence of values it produces is exactly determined by what you pass to the initial call to seed(). As a result, if you call seed() with a known value, then you can predict exactly what series of values you'll get from subsequent calls to random(). If you call seed() with a truly random number, then calls to random() will be correspondingly random.

(But that begs the question: if you have random number to pass to seed(), why bother calling random() at all?)

查看更多
登录 后发表回答