生成一个罕见的数字之间的两个号码随机数 [英] Generate Random number between two number with one rare number

查看:198
本文介绍了生成一个罕见的数字之间的两个号码随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在c。使用此生成两个数字之间的随机数。

i can generate random number between two numbers in c using this..

arc4random()%(high-low+1)+low;

那么现在我的要求是......我想作出一些罕见的....这就是意味着,如果

then now my requirement is...i want to make a number rare....thats mean if

高= 5,
低= 1,
和稀有= 3,

high=5, low=1, and rare=3,

3比将非常很少出现比1,2,4和5 ...

than 3 will be appeared much rarely than 1,2,4 and 5...

感谢

推荐答案

您可以使用表格来计算你的最终摇,类似于笔和纸的RPG游戏如何做到这一点同类型的计算:

You can use tables to calculate your final roll, similar to how pen and paper RPGs do this same type of calculation:

卷1个D 21(容易可能的W / code)。

Roll 1 D 21 (easily possibly w/ code).


  • 如果你得到1-5,它算作是1

  • 如果你得到6-10,它算作是2

  • 如果你得到11-15,它算作是4

  • 如果你得到16-20,它算作是5

  • 如果你得到一个21,它算作是3

这个选项的好处是你得到你所处理的确切概率感很强。你可以得到每个数字究竟是如何稀有或常见的是一种感觉,你会得到的每个数字是如何常见的是精细的控制,相较于其他的数字。

The advantage to this option is you get a strong sense of the exact probabilities you are dealing with. You can get a feeling of exactly how rare or common each number is, and you get fine-grained control of how common each number is, in comparison to the other numbers.

您也可以使用部分生成表。使用最小公倍数来确定一个共同的基础。这基地是最大的随机数的大小,您将需要。然后,把所有的分数以相同条款。使用所得numerators以确定表中的每个数的范围内的大小。

You could also use fractions to generate the table. Use the Least Common Multiple to determine a common base. That base is the max random number size you will need. Then, put all the fractions in like terms. Use the resulting numerators to determine the size of the range for each number in the table.

通过此自动化的解决方案,在输入数字非常容易在相对于彼此理解。例如:

With this automated solution, the input numbers are very easy to understand in relation to each other. E.g:


  • 1/4 1

  • 1/4 2

  • 1/4 4

  • 1/5 5

  • 1/20 3

这将产生一个表像这样:

This would generate a table like so:

LCM = 20


  • 1-5 = 1(同类项 - 5/20)

  • 6-10 = 2(5/20)

  • 11-15 = 4(5/20)

  • 16-19 = 5(4/20)

  • = 20(1/20)

一些更多的LCM:<一href=\"http://en.wikipedia.org/wiki/Least_common_multiple\">http://en.wikipedia.org/wiki/Least_common_multiple

这篇关于生成一个罕见的数字之间的两个号码随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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