24 lines
711 B
C#
24 lines
711 B
C#
|
|
using System;
|
||
|
|
namespace 随机数
|
||
|
|
{
|
||
|
|
class Program
|
||
|
|
{
|
||
|
|
static void Main(string[] args)
|
||
|
|
{
|
||
|
|
#region 知识点一 生成随机数对象
|
||
|
|
//固定写法
|
||
|
|
// Random 关键字
|
||
|
|
Random r = new Random();
|
||
|
|
#endregion
|
||
|
|
|
||
|
|
#region 知识点二 生成随机数
|
||
|
|
int i = r.Next(); //生成一个非负随机整数
|
||
|
|
Console.WriteLine(i);
|
||
|
|
i = r.Next(100); //生成一个非负随机整数,范围为[0, 100)
|
||
|
|
Console.WriteLine(i);
|
||
|
|
i = r.Next(50, 100); //生成一个非负随机整数,范围为[50, 100)
|
||
|
|
Console.WriteLine(i);
|
||
|
|
#endregion
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|