使用C#在24,随机大小部件拆分值 [英] Split value in 24 randomly sized parts using C#
问题描述
我有一个值,说20010.我要超过24小时随机划分这个值。所以基本上值分成24槽的大阵,所有插槽都随机大。
I have a value, say 20010. I want to randomly divide this value over 24 hours. So basically split the value into a 24 slot big array where all slots are randomly big.
可能是有什么好办法解决这个使用C#?
What could be a good way solving this using C#?
推荐答案
随机抽取23(不是24)号,(不重复),范围为1至20009.添加0和20010列表和顺序,这些号,每两个连续数之间的差给你一个槽值
Draw 23 (not 24) numbers at random, (without duplicates), in the range 1 to 20009. Add 0 and 20010 the list and order these numbers, the difference between each two consecutive number gives you one slot value.
一个在线的方法也可以通过在一个时间绘制一个值和从锅减去它,当数比左侧的量更大的拉丝重新。然而,这种方法可能导致槽的大小的一个更大的偏差。
An online approach is also possible by drawing one value at a time and subtracting it from the "pot", drawing anew when the number is bigger than the amount left. This approach however may lead to a greater deviation of the size of the slots.
这篇关于使用C#在24,随机大小部件拆分值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!