马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- using System;
- namespace ConsoleApplication1
- {
- class Program
- {
- public static int[] GetRandomUnrepeatArray(int minValue, int maxValue, int count)
- {
- Random rnd = new Random();
- int length = maxValue - minValue + 1;
- byte[] keys = new byte[length];
- rnd.NextBytes(keys);
- int[] items = new int[length];
- for (int i = 0; i < length; i++)
- {
- items[i] = i + minValue;
- }
- Array.Sort(keys, items);
- int[] result = new int[count];
- Array.Copy(items, result, count);
- return result;
- }
- static void Main(string[] args)
- {
- Console.Write("\nMinIntNum: ");
- string d1 = Console.ReadLine() ;
- Console.Write("\nMaxIntNum: ");
- string d2 = Console.ReadLine();
- Console.Write("\nNums: ");
- string d3 = Console.ReadLine();
- int[] rs = GetRandomUnrepeatArray(Convert.ToInt32(d1), Convert.ToInt32(d2), Convert.ToInt32(d3));
- Console.WriteLine("\nRandom is: ");
- for (int i = 0; i < rs.Length ; i++)
- {
- Console.WriteLine(rs[i].ToString());
- }
- Console.ReadLine();
- }
- }
- }
|