简体   繁体   English

set.seed()函数在R中影响随机

[英]set.seed() function influence into random in R

Today i first met a set.seed function in R. It's useful in same times, and i understand how to use it. 今天我第一次在R中遇到了一个set.seed函数。它在同一时间很有用,我理解如何使用它。 But i have a small problem - how to choose a real good number as a first parameter in this function? 但我有一个小问题 - 如何选择一个真正的好数字作为这个函数的第一个参数?

From that question a get another - how the first parameter from set.seed() function influence into random in R? 从那个问题得到另一个 - 来自set.seed()函数的第一个参数如何影响到R中的随机? Maybe if i understand the last, i will take the answer of first. 也许如果我理解了最后一个,我会先回答。 Thanks a lot. 非常感谢。

In a nutshell: 简而言之:
By setting set.seed() you specify the starting-point for all "pseudo random number generators" that create the random numbers in R . 通过设置set.seed()您可以为在R中创建随机数的所有“伪随机数生成器”指定起始点。 See ?set.seed ?set.seed

As computers are very deterministic there is nothing like a real "random number". 由于计算机非常具有确定性,因此没有任何东西像真正的“随机数”。 Computers always have to use an algorithm to generate so called "pseudo random numbers". 计算机总是必须使用算法来生成所谓的“伪随机数”。 These generators/algorithms work (very often) iterative so the next number is influenced by its predecessor. 这些生成器/算法(通常)迭代工作,因此下一个数字受其前身的影响。 set.seed() defines the initial predecessor and thereby makes pseudo random numbers reproducible. set.seed()定义了初始前导,从而使伪随机数可重现。 Which number you choose is irrelevant in most cases. 在大多数情况下,您选择哪个号码无关紧要。

(see here: http://en.wikipedia.org/wiki/Pseudorandom_number_generator ) (见这里: http//en.wikipedia.org/wiki/Pseudorandom_number_generator

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM