在产生随机数方面,什么是种子? [英] What is a seed in terms of generating a random number?

查看:124
本文介绍了在产生随机数方面,什么是种子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在产生随机数方面,什么是种子?

What is a seed in terms of generating a random number?

我需要生成数百到数千个随机数,我已经阅读了很多关于使用种子。什么是种子?是随机数字开始的种子吗?例如,如果我将我的种子设置为5将生成数字从5到我的限制是什么?所以它永远不会给我3例如。

I need to generate hundreds to thousands of random numbers, I have read a lot about using a "seed". What is a seed? Is a seed where the random numbers start from? For example if I set my seed to be 5 will it generate numbers from 5 to whatever my limit is? So it will never give me 3 for example.

我使用C ++,所以如果你提供任何例子,它将是很好,如果是在C ++。

I am using C++, so if you provide any examples it'd be nice if it was in C++.

谢谢!

推荐答案

因为使用确定性算法来计算值,并且概率不起作用。

What is normally called a random number sequence in reality is a "pseudo-random" number sequence because the values are computed using a deterministic algorithm and probability plays no real role.

种子是序列的起始点并保证,如果你从同一个种子开始,你会得到相同的数字序列。这对于例如调试是非常有用的(当您在程序中寻找错误需要能够重现问题并研究它时,非确定性程序将更难调试,因为每次运行都会不同) 。

The "seed" is a starting point for the sequence and the guarantee is that if you start from the same seed you will get the same sequence of numbers. This is very useful for example for debugging (when you are looking for an error in a program you need to be able to reproduce the problem and study it, a non-deterministic program would be much harder to debug because every run would be different).

如果你只需要一个随机数字序列,不需要重现它,那么只需使用当前时间作为种子...例如:

If you need just a random sequence of numbers and don't need to reproduce it then simply use current time as seed... for example with:

srand(time(NULL));

这篇关于在产生随机数方面,什么是种子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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