随机函数(在任何编程语言中)是否有偏见? [英] Is Random function (in any programming language) biased?

查看:49
本文介绍了随机函数(在任何编程语言中)是否有偏见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编程语言中的函数Random 是不是有偏见?毕竟,算法需要基于某些东西,这会产生偏差.根据本网站 https://mathbits.com/MathBits/CompSci/LibraryFunc/rand.htmrand() 函数需要一个起始编号,称为seed.它指出

Is the function Random in programming languages not biased? After all, the algorithms need to be based on something, and that can generate bias. According to this website https://mathbits.com/MathBits/CompSci/LibraryFunc/rand.htm, rand() function needs a start number, called seed. It states that

rand() 函数生成一个伪随机序列

the rand( ) function generates a pseudo-random sequence

我不完全理解它背后的逻辑.如果不是真的随机(伪随机),有没有办法让它完全随机?

I don't completely understand the logic behind it. If it's not really random (pseudo-random), is there a way to make it perfectly random?

推荐答案

根据定义,函数将给定的输入映射到给定的输出.对于伪随机生成器,这意味着它映射给定的种子".到给定的随机数字序列.对于这样的生成器,甚至开始生成随机"数字,种子本身必须具有一些随机性.并且有许多种子来源用于此目的,包括——

By definition, functions map a given input to a given output. For a pseudorandom generator, that means it maps a given "seed" to a given sequence of random-looking numbers. For such a generator to even begin to generate "random" numbers, the seed has to have some randomness itself. And there are many sources of the seed for this purpose, including—

  • 高分辨率时间戳,
  • 输入设备的时间,
  • 热噪声,
  • 大气噪音,以及
  • 上述两个或多个来源的组合.

此外,一般而言,种子越长,随机"种子的种类就越多.伪随机发生器可以产生的序列.

Also, in general, the longer the seed is, the greater the variety of "random" sequences a pseudorandom generator can produce.

不同的伪随机数生成器 (PRNG) 具有不同的品质.如果特定的 PRNG 本身是坏的",则没有种子选择策略可以使其更好".随机数生成器 (RNG) 的选择将取决于将使用随机数的应用程序类型,您并没有真正指定您想到的应用程序类型:

Different pseudorandom number generators (PRNGs) have different qualities. If a particular PRNG is itself "bad", no seed selection strategy can make it "better". The choice of random number generator (RNG) will depend on what kind of application will use the random numbers, and you didn't really specify what kind of application you have in mind:

  • 如果随机数旨在以任何方式进一步提高信息安全性(例如,它们用作随机加密密钥、随机数或密码),那么只有一个 加密 RNG 即可.
  • 如果随机"数字必须在以后可重现,然后高质量的 种子 PRNG 具有要使用的.有几个好的和坏的选择 对于这样的 PRNG.从这个意义上说,C 中的 rand 函数使用了一个 未指定的算法,这阻碍了可重复的随机性"目标.
  • If the random numbers are intended to further information security in any way (e.g., they serve as random encryption keys, nonces, or passwords), then only a cryptographic RNG will do.
  • If the "random" numbers have to be reproducible at a later time, then a seeded PRNG of high quality has to be used. There are several good and bad choices for such a PRNG. In this sense, the rand function in C uses an unspecified algorithm, which hampers the goal of reproducible "randomness".

这篇关于随机函数(在任何编程语言中)是否有偏见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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