为每个生成的随机数更改种子 [英] Change seed for every generated random number

查看:45
本文介绍了为每个生成的随机数更改种子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您使用种子作为自 1970 年 1 月以来经过的时间(以秒为单位)生成随机数,就像在 microsoft library 中一样.但是您在生成每个随机数后更改种子.这会给出一个真正随机的结果.为什么或为什么不?

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?

编辑我只是有一个问题的一部分.如果我得到的种子是非确定性的怎么办.举个小例子,假设种子是由一个已经存在的 TRNG(真随机数生成器)生成的.换句话说,如果我可以以某种方式使种子非确定性,我是否能够生成随机序列,即非确定性序列.为什么或为什么不?

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() 函数时:如果您在确定的时间调用该函数(例如每秒一次) 结果将是确定性的.如果您随机调用该函数,结果将是随机的.

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.

更准确地说,这取决于您调用 seed() 函数的值.如果您使用确定性值调用 seed(),则对 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.

软件随机生成器是完全确定的;它产生的值序列完全取决于您传递给对seed() 的初始调用的内容.因此,如果您使用已知值调用 seed(),那么您可以准确地预测从后续调用 random() 中将获得哪些系列的值.如果您使用真正的随机数调用 seed(),则对 random() 的调用将相应地随机.

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.

(但这引出了一个问题:如果你有随机数传递给seed(),为什么还要调用random()呢?)

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

这篇关于为每个生成的随机数更改种子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆