具有较高概率给出低值的随机数生成器? [英] Random number generator with higher probabilities of giving low values?

查看:18
本文介绍了具有较高概率给出低值的随机数生成器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何生成伪随机数(最好在 Lua 中),其中生成器有更高的概率给出小数?

How can I generate a pseudo-random number (preferably in Lua), where the generator has a higher probability of giving small numbers?

就我而言,我想在游戏中随机给出一个分数,获得较低分数的情况很常见,但很少出现较高的分数.我见过使用表格的加权随机数生成器,但它不符合我的计划.我只想指定最小值 (0) 最大值(变量)并确保大多数数字保持较低.

In my case, I want to give a random score in a game, where it's common to obtain the lower scores, but higher ones appear rarely. I've seen weighted random number generators that use a table, but it doesn't fit my plan. I just want to specify the minimum (0) the maximum (variable) and ensure most numbers stay low.

我确信这可以通过简单的数学运算实现,但我不记得是哪一个.喜欢过滤 math.random 的常规输出,不需要真正的随机生成器.

I am sure this is possible with a simple mathematical operation, but I cannot remember which one it was. Like to filter the regular output of math.random, no need for a really random generator.

推荐答案

这可能不是您要找的,因为它不是平滑偏置的钟形曲线,但为什么不创建两个步骤呢?定义获得较低范围分数的概率,如果匹配,则您的范围是较低范围.否则,您的范围是从低范围的顶部到高范围的末端.

This may not be what you're looking for, since it's not a smoothly biased bell curve, but why not create two steps? Define a probability of getting a lower-range score and if you match it, your range is the lower range. Otherwise, your range is from the top of the low range to the end of the high range.

最终效果是您通常会得到低分,但有时您会得到高分.我敢打赌它看起来会很不错,而且很简单.

The net effect is that you'd usually get a low score, but sometimes you'd get high scores. I bet it would look pretty good, and is very simple.

你怎么看?

这篇关于具有较高概率给出低值的随机数生成器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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