C#取随机数注意事项
2013-12-08 16:51
309 查看
注意,随机数范围,取下限值,但不取上限值。
//随机数放入数组,但不能重复
Random random = new Random();//随机对象
List<int> iList = new List<int>();//列表对象
while (true)
{
int i = random.Next(1, 10);//注意随机数范围,取下限值,但不取上限值
bool b = iList.Exists(delegate(int n) { if (n == i)return true; else return false; });
if (!b)
{
iList.Add(i);
}
if (iList.Count > 8) break;
}
iList.Sort();
iList.ForEach(delegate(int i) { Console.WriteLine(i); });
//随机数放入数组,但不能重复
Random random = new Random();//随机对象
List<int> iList = new List<int>();//列表对象
while (true)
{
int i = random.Next(1, 10);//注意随机数范围,取下限值,但不取上限值
bool b = iList.Exists(delegate(int n) { if (n == i)return true; else return false; });
if (!b)
{
iList.Add(i);
}
if (iList.Count > 8) break;
}
iList.Sort();
iList.ForEach(delegate(int i) { Console.WriteLine(i); });
相关文章推荐
- 【编程开发】C语言中随机数rand使用注意事项
- C#中随机数生成要注意的一点事项
- C++中生成随机数的几点注意事项
- 随机数极其注意事项
- 生成随机数的方法及注意事项()
- Eclipse Platform Version: 3.4.0 构建webServers 项目注意事项
- 关于完成端口IOCP异步接收连接函数AcceptEx注意事项
- [开发笔记]-jQuery获取checkbox选中项等操作及注意事项
- 处理AIX文件系统空间不足常用命令及注意事项
- spring boot 添加jsp支持注意事项
- postgresql timestamp timestamptz 使用注意事项
- 提高百度的收录质量的注意事项
- VS编程中注意事项
- AE常用代码(标注要素、AE中画带箭头的线、如何获得投影坐标、参考坐标、投影方式、FeatureCount注意事项)
- windows7安装oracle 10g安装过程及注意事项
- Redis-Redi事务注意事项
- 实现Java跨平台运行的十二个注意事项
- ACM注意事项及一些小技巧
- 采购谈判注意事项--采购员必读
- linux连接internet前的注意事项