赌场随机 [英] Casino Randoms

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

问题描述

如何设置获得特定输出的百分比机会.像这样:

我有可以在其中找到一些物品的游戏.该物品可以有最大生命",例如

最大最大寿命为200,最小最大寿命为1.

当我生成最大寿命时,我现在使用random.next(1,201)来获得1到200之间的随机输出.但是我想使最大寿命中50%的项目小于100最大寿命,而仅使1%最大寿命为200.

How can i set a % chance of getting a certain output. Like this:

I have game where i can find some items. The item can have Max Life e.g.

The Max Max Life is 200 and the minimum max life is 1.

When i generate the max life I use random.next(1, 201) now to get a random output between 1 and 200. But I want to make 50% of the items Max Life less than 100 max life, and only 1% of the items Max Life to be 200.

How can i do that?

推荐答案

您的要求不是很清楚.但是,假设您有自己的生命概率分布:


寿命 概率 概率.密度
1-99 50% 0.00505
100-199 49% 0.00490
200-200 1% 0.01005


第三列包含离散的概率密度
(请注意,我已根据需要任意提高了数字200的密度,以使累积总和为1).

现在,如果您以均匀的概率提取随机数(如Random一样),则必须将累积概率函数等式化以获取分布的对应数.
由于密度的粒度为10^-5,因此我们可以为Random选择间隔0-9999 9,并且仅使用整数,方法是:

随机结果 选择生活
1
2
..
49490-49994 99
49995-50484 100
50485-50974 101
... ..
98505 -98994 199
98995-99999 200


实现这样的逻辑几乎是微不足道的:

You''re request isn''t very clear. However, suppose you have your own probability distribution for lifes:


lifesprobabilityprob. density
1 - 9950%0.00505
100 - 19949%0.00490
200 - 2001%0.01005


Where third column holds discrete densities of probability
(note I''ve arbitrarly boosted number 200 density to make cumulative sum be 1, as required).

Now, if you extract a random number with uniform probability (as Random does) you''ve to equate the cumulative probability functions to get the corrensponding number of your distribution.
Since the granularity of our densities is 10^-5, we can choose the interval 0-99999 for Random and use only integer numbers, this way:

Random outcomechoosen life
0-5041
505-10102
.....
49490-4999499
49995-50484100
50485-50974101
.....
98505-98994199
98995-99999200


Implementing such logic is almost trivial:

public static int myNext(Random r)
{
    n = r.Next(100000);
    if (n < 49995)
    {
        return 1 + (n / 505);
    }
    else if (n < 98995)
    {
        return 100 + ((n - 49995) / 490);
    }
    else
    {
        return 200;
    }
}




:)




:)


如果我在上面指定的是正确的,则可以生成两次随机数.
首先执行random.next(1,101).

如果返回1-50,则您处于100以下的选择中,然后执行random.next(1,100)以获取1到100之间的数字作为您的Life值.

如果它返回51-99,则说明您处于100-199的选择范围内,因此执行random.next(101,200)来获取您的Life值.

如果初始随机数返回100,则您的生命"值为200.
If what I specified above it true, you can generate random numbers twice.
First do a random.next(1, 101).

If it returns 1-50 then you are in the under 100 selection and then do random.next(1, 100) to get a number between 1 and 100 for your Life value.

If it return of 51-99 then you are in the 100-199 selection, so do a random.next(101, 200) to get your Life value.

If the initial random returns 100, then your Life value is 200.


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

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