Copy Code code as follows:
Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.Text;
Namespace EC
{
<summary>
Random function
</summary>
public class Randomobject
{
#region Digital Random number
<summary>
Digital random number
</summary>
<param name= "n" > Build length </param>
<returns></returns>
public static string Randnum (int n)
{
char[] Arrchar = new char[] {' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 '};
StringBuilder num = new StringBuilder ();
Random rnd = new Random (DateTime.Now.Millisecond);
for (int i = 0; i < n; i++)
{
Num. Append (arrchar[rnd. Next (0, 9)]. ToString ());
}
Return Num. ToString ();
}
#endregion
#region number and letter random numbers
<summary>
Number and letter random numbers
</summary>
<param name= "n" > Build length </param>
<returns></returns>
public static string Randcode (int n)
{
char[] Arrchar = new char[]{
' A ', ' B ', ' d ', ' C ', ' e ', ' f ', ' g ', ' h ', ' I ', ' j ', ' K ', ' l ', ' m ', ' n ', ' P ', ' r ', ' Q ', ' s ', ' t ', ' u ', ' V ', ' w ', ' z ', ' y ', ' x ',
' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ',
' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J ', ' K ', ' L ', ' M ', ' N ', ' Q ', ' P ', ' R ', ' T ', ' S ', ' V ', ' U ', ' W ', ' X ', ' Y ', ' Z '
};
StringBuilder num = new StringBuilder ();
Random rnd = new Random (DateTime.Now.Millisecond);
for (int i = 0; i < n; i++)
{
Num. Append (arrchar[rnd. Next (0, Arrchar.length)]. ToString ());
}
Return Num. ToString ();
}
#endregion
Random number of #region letters
<summary>
Random Number of letters
</summary>
<param name= "n" > Build length </param>
<returns></returns>
public static string Randletter (int n)
{
char[] Arrchar = new char[]{
' A ', ' B ', ' d ', ' C ', ' e ', ' f ', ' g ', ' h ', ' I ', ' j ', ' K ', ' l ', ' m ', ' n ', ' P ', ' r ', ' Q ', ' s ', ' t ', ' u ', ' V ', ' w ', ' z ', ' y ', ' x ',
'_',
' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J ', ' K ', ' L ', ' M ', ' N ', ' Q ', ' P ', ' R ', ' T ', ' S ', ' V ', ' U ', ' W ', ' X ', ' Y ', ' Z '
};
StringBuilder num = new StringBuilder ();
Random rnd = new Random (DateTime.Now.Millisecond);
for (int i = 0; i < n; i++)
{
Num. Append (arrchar[rnd. Next (0, Arrchar.length)]. ToString ());
}
Return Num. ToString ();
}
#endregion
#region Date Random function
<summary>
Date Random function
</summary>
<param name= "RA" > Length </param>
<returns></returns>
public static string Daterndname (Random ra)
{
DateTime d = DateTime.Now;
string s = null, Y, M, DD, H, MM, SS;
y = d.year.tostring ();
m = d.month.tostring ();
if (M.length < 2) m = "0" + m;
dd = d.day.tostring ();
if (DD. Length < 2 DD = "0" + dd;
h = d.hour.tostring ();
if (H.length < 2) H = "0" + H;
mm = D.minute.tostring ();
if (mm. Length < 2) mm = "0" + mm;
SS = D.second.tostring ();
if (ss. Length < 2) ss = "0" + SS;
s + + y + M + dd + H + mm + ss;
s + = ra. Next (100, 999). ToString ();
return s;
}
#endregion
#region Build GUID
<summary>
Generate GUID
</summary>
<returns></returns>
public static string GetGuid ()
{
System.Guid g = System.Guid.NewGuid ();
return g.tostring ();
}
#endregion
}
}