如何使用随机函数在c#中生成随机数,新/下一个数字比前一个更大......? [英] How to generate random number in c# using random function, new/next number is grater than previous one...?

查看:146
本文介绍了如何使用随机函数在c#中生成随机数,新/下一个数字比前一个更大......?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用随机函数在c#中生成随机数,新/下一个数字比前一个更重要 ...?

解决方案

从MSDN开始阅读文档。

随机类 [ ^ ]

你有一些不错的样品。



要检查新数字是否大于前一个,您需要存储旧值,然后与新值进行比较。

这可以循环完成,直到你的条件已经完成。


如果你必须生成增加随机数的有限序列,那么你可以采用这种方法:使用标准随机生成器生成数字并将它们存储到一个数组中。最后对数组进行排序并使用其项目作为必需(增加)序列。


您好,



您可以生成一个初始值随机数,然后将该数字与上一个生成的数字相加。



随机r =  Random(); 
列表< double>数;
numbers.Add(r.next());
for int i = 0 ; i< whatever_limit; i ++){
numbers.Add(r.Next + numbers [i]);
}





希望这有帮助。



LG


How to generate random number in c# using random function, new/next number is grater than previous one...?

解决方案

You start with MSDN and read the documentation.
Random Class[^]
You have some pretty good samples there.

To check if the new number is greater than the previous, you need to store the old value and then compare with the new.
This can be done in a loop until your condition is fulfilled.


If you have to generate a finite sequence of increasing random numbers then you might follow this approach: generate the numbers using the standard random generator and store them into an array. Finally sort the array and use its items as the required (increasing) sequence.


Hi,

You can generate an initial random number and then sum that number to the previous generated one.

Random r = new Random();
List<double> numbers;
numbers.Add(r.next());
for(int i = 0;i<whatever_limit;i++){
numbers.Add(r.Next + numbers[i]);
}



Hope this helped.

LG


这篇关于如何使用随机函数在c#中生成随机数,新/下一个数字比前一个更大......?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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