把一个号码到随机不等部分 [英] Dividing a number into random unequal parts

查看:94
本文介绍了把一个号码到随机不等部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我试图让一个脚本,将随机分成4的值转换成12个不同的变量。我想不出一个好办法,正确做到这一点。我想到了随机数字,让他们接近0.33(4 1/12),但往往会导致最后的几个数字被underprioritized。任何人都尝试过这样的事情之前,或对如何做任何伟大的想法,这是随机的,均匀不均匀地?

So I am trying to make a script that will randomly split a value of 4 into 12 different variables. I can't think of a good way to do this properly. I thought about randomizing numbers so that they are close to 0.33 (1/12 of 4) but that would often lead to the last few numbers being underprioritized. Anyone tried anything like this before or have any great ideas for how to make this as random and evenly uneven as possible?

推荐答案

12产生的随机数从您最喜爱的随机数生成器,给他们打电话 r1..r12

Generate 12 random numbers from your favourite random number generator, call them r1..r12.

添加它们,请致电总和

Add them all up, call the sum sum.

您的第一个随机分数 4 (R1 /和)* 4 。其余的应该是显而易见的。

Your first random fraction of 4 is (r1/sum)*4. The rest should be obvious.

这篇关于把一个号码到随机不等部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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