///
// 發現太多的随機數産生算法,都很繁。
// 其實,c#自帶的資料算法即可很好的實作!
// 正所謂“蓦然回首,那人卻在,燈火闌珊處”!
///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// --------------------------------------------
// 随機數産生
// --------------------------------------------
Console.WriteLine("産生随機數1-100");
SortedList sl = new SortedList();
sl.Clear();
for (int no = 0; no < 1 * 100; no++)
{
sl[no + 1] = no + 1;
}
Console.WriteLine("整理随機數1-100");
ArrayList al = new ArrayList();
Random r = new Random();
for (int NN = 1 * 100; NN > 0; NN--)
{
if (NN == 1)
{
al.Add(sl.GetByIndex(0));
break;
}
int nTemp = r.Next(0, NN);
al.Add(sl.GetByIndex(nTemp));
sl.RemoveAt(nTemp);
}
string sd0;
sd0 = "";
for (int i = 0; i < al.Count; i++)
{
sd0 = sd0 + (al[i].ToString() + ";");
}
Console.WriteLine(sd0);
}
}
}