Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace www.cnblogs.com. rock_chen
{
Class Program
{
/// <Summary>
/// If Random. Next (100) is known, Random data from 1 to is generated.
/// </Summary>
/// <Param name = "args"> </param>
Static void Main (string [] args)
{
GenerateRandom generateRandom = new GenerateRandom ();
Var result = generateRandom. Calc ();
Console. WriteLine (string. Join (",", result ));
Console. WriteLine ();
Console. WriteLine (string. Join (",", result. OrderBy (p => p). ToArray ()));
Console. Read ();
}
}
Public class GenerateRandom
{
Random random = new Random ();
Public int [] Calc ()
{
Int [] ary = new int [100];
Int count = 0;
Int currentIndex = 0;
Int k = 0;
While (count & lt; 100)
{
Var index = RandomInt ();
If (ary [currentIndex] = 0)
{
Ary [currentIndex] = index;
Ary [index-1] = currentIndex + 1;
CurrentIndex = index-1;
Count = 2;
Continue;
}
If (ary [index-1] = 0 & currentIndex! = Index-1)
{
Ary [index-1] = ary [currentIndex];
Ary [currentIndex] = index;
CurrentIndex = index-1;
Count ++;
}
Else
{
While (k <100 & ary [k]> 0)
{
K ++;
}
If (currentIndex! = K & k <100)
{
Ary [k] = ary [currentIndex];
Ary [currentIndex] = k + 1;
CurrentIndex = k;
Count ++;
}
}
}
Return ary;
}
Public int RandomInt ()
{
Return (random. Next (1, 10)-1) * 10 // 10-80 10 digits
+ Random. Next (1, 10) + random. Next (1, 10)-1 // limit 17
+ (Random. Next (1, 10) & 3); // 0-3
}
}
}
From I'm CY