各位帮忙看看,为什么我的这段代码输出学号后四位之后生成不出随机数来,谢谢了...
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleAppTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入你学号的后四位");
int seed = int.Parse(Console.ReadLine());
Random ran = new Random(seed);
List<int> arr = new List<int>();
int count = 0;
while (count < 4)
{
int a = ran.Next(1, 9);
if (!arr.Contains(a))
{
arr.Add(a);
count++;
}
}
foreach (int i in arr)
{
Console.Write("(0,-4}", i);
}
}
}
}
--------------------编程问答-------------------- long tick = DateTime.Now.Ticks;
Random ran = new Random((int)(tick & 0xffffffffL) | (int) (tick >> 32));
--------------------编程问答-------------------- Random rand = new Random(Guid.NewGuid().GetHashCode());
补充:.NET技术 , C#