Using System;
Using System.Configuration;
Using System.Text;
Using System.Data;
Namespace ZC. Utils
{
<summary>
A summary description of the Assistant.
</summary>
public sealed class Randomhelper
{
#region
<summary>
Randomly obtained from a string, the specified number of strings.
</summary>
<param name= "Allchar" ></param>
<param name= "Codecount" ></param>
<returns></returns>
public static string Getrandomcode (string allchar, int codecount)
{
String Allchar = "1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
string[] Allchararray = Allchar.split (', ');
String randomcode = "";
int temp =-1;
Random rand = new Random ();
for (int i=0;i<codecount;i++)
{
if (temp! =-1)
{
Rand = new Random (temp*i* ((int) DateTime.Now.Ticks));
}
int t = rand. Next (allchararray.length-1);
while (temp = = t)
{
t = rand. Next (allchararray.length-1);
}
temp = t;
Randomcode + = allchararray[t];
}
return randomcode;
}
<summary>
Randomly obtained from a string, the specified number of strings.
</summary>
<param name= "Allchar" ></param>
<param name= "Codecount" ></param>
<returns></returns>
public static string Getrandomcode (int codecount)
{
String Allchar = "1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
string[] Allchararray = Allchar.split (', ');
String randomcode = "";
int temp =-1;
Random rand = new Random (Getrandomseed ());
for (int i = 0; i < Codecount; i++)
{
if (temp! =-1)
{
Rand = new Random (temp * i * ((int) DateTime.Now.Ticks));
Rand = new Random (Getrandomseed ());
}
int t = rand. Next (allchararray.length-1);
while (temp = = t)
{
t = rand. Next (allchararray.length-1);
}
temp = t;
Randomcode + = allchararray[t];
}
return randomcode;
}
static int Getrandomseed ()
{
byte[] bytes = new Byte[4];
System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider ();
Rng. GetBytes (bytes);
Return Bitconverter.toint32 (bytes, 0);
}
#endregion
}
}
. NET generates random numbers