CopyCode The Code is 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>
/// Random Number
/// </Summary>
/// <Param name = "N"> generation 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 random numbers and letters
/// <Summary>
/// Random numbers and letters
/// </Summary>
/// <Param name = "N"> generation length </param>
/// <Returns> </returns>
Public static string randcode (int n)
{
Char [] arrchar = new char [] {
'A', 'B', 'D', 'C', 'E', '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', '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 Random Number
/// <Summary>
/// Random number of letters
/// </Summary>
/// <Param name = "N"> generation length </param>
/// <Returns> </returns>
Public static string randletter (int n)
{
Char [] arrchar = new char [] {
'A', 'B', 'D', 'C', 'E', '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', '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 generation guid
/// <Summary>
/// Generate guid
/// </Summary>
/// <Returns> </returns>
Public static string getguid ()
{
System. guid G = system. guid. newguid ();
Return G. tostring ();
}
# Endregion
}
}