生成随机数lyk,其总数与输入值相同。 [英] generate random numbers lyk that its total is same as input value.
本文介绍了生成随机数lyk,其总数与输入值相同。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hiii,
有一个文本框,我必须输入值(lyk i输入1500),我必须生成i 1000 gridview中的随机值,此值介于.01到3.0之间。并且这个值总数等于我们输入的1500,那么我该如何做或者提供代码来生成上面提到的范围之间的随机值谢谢.....
hiii,
one textbox is there and in which i have to enter the value(lyk i enter 1500) and i have to generate i 1000 random value in gridview and this values are in between .01 to 3.0. and this values total is equal to 1500 which we enter so how can i do or provide me code to generate random value in between the range that i above mention thank you.....
推荐答案
试试这段代码:
try this code:
public static IEnumerable<int> GetRandom()
{
var rand = new Random();
while (true)
{
yield return
rand.Next(.01, 3);
}
}
public static List<int> GetThirtyThatAddToTwoHundred()
{
do
{
var current = GetRandom().Take(1000);
if (1500 == current.Sum())
{
return current.ToList();
}
} while (true);
}
**取自StackOverFLow **
**taken from StackOverFLow **
这篇关于生成随机数lyk,其总数与输入值相同。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文