Code Random random = new Random(unchecked((int)DateTime.Now.Ticks)); List<int> list = new List<int>(5); for (int i = 0; i < 5; i++) { int temp = random.Next(1, 35); if (list.Contains(temp)) { --i; continue; } else list.Add(temp); } 转载于:https://www.cnblogs.com/cxfcxf8/archive/2008/05/05/1183066.html