随机数概率 [英] random number with probability
本文介绍了随机数概率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法让随机数生成的数字概率最高?
例如。
随机没有1 20%
随机没有2(更高的百分比) - 60%
随机没有3 20%
解决方案
< blockquote>我不知道任何内置方式,但你可以总是这样做......
展开 | 选择 | 换行 | 行号
大。也可以用。我先尝试一下,让你知道我的结果。 Thx bro;)
我不是一个c#类型的人,但是@garyTexmo编写的代码对于一般情况来说有点难以实现。
在我的例子中,我假设方法/函数Rand()返回一个零到一的浮点值,甚至是分布。
展开 | 选择 | Wrap | 行号
Is there any way to make a number that generated by random number is the highest probability among all?
eg.
random no 1 20%
random no 2 (Higher percentage) - 60%
random no 3 20%解决方案I don''t know of any built in way, but you could always do something like...
Expand|Select|Wrap|Line Numbers
Great. Can be used too. I have a try first den I let u know my result. Thx bro ;)
I''m not a c# kind of guy, but the code @garyTexmo wrote is a little bit difficult to implement for the general case.
In my example, I assume that the method/function Rand() returns a floating point value in the range of zero to one, with even distibution.
Expand|Select|Wrap|Line Numbers
这篇关于随机数概率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文登录 关闭
扫码关注1秒登录发送“验证码”获取 | 15天全站免登陆