生成范围内的随机数 [英] Generate Random number within a range

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

问题描述





我想在(-10到10)的值范围之间生成一个随机数。

对于此范围内的任何尝试次数,生成的随机数应相同。



如果-10到10给4.526325631

那么如果我给-10到10 100次然后生成的数字应该是4.526325631。



我怎样才能实现它?

Hi,

I want to generate a random number between a range of value say from (-10 to 10).
The generated random number should be same for any number of attempts in this range.

If -10 to 10 give 4.526325631
then if i give -10 to 10 for 100 times then the number generated should be 4.526325631.

How can i acheive it?

推荐答案

不要使用随机数。



随机数这个短语的哪一部分令你感到困惑?

当你在一个上限和下限之间产生一个随机数时,你不知道这个数字是什么 - 这就是随机的整个想法。随着时间的推移和足够的数字,它会趋向于上限和下限的平均值,但你不能将其偏向任何特定值 - 或者它会失去所有随机性。
Don''t use random numbers.

What part of the phrase "Random number" is confusing you?
When you generate a random number between an upper an a lower limit you have no idea what the number will be - that is the whole idea of "random" Over time and sufficient numbers it will trend to the mean of the upper and lower bounds, but you cannot skew it towards any particular value - or it looses all semblance of randomness.


请参阅文章 [ ^ ]


你好,



你能说清楚,你说你想要一个随机数但是那么你说的数字应该总是4.526325631。
Hello,

Can you please clarify, you state you want a random number but then you state the number should always be 4.526325631.


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

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