A class that randomly generates simplified Chinese characters

Source: Internet
Author: User
Static string [] fonts (INT strlength)
// Return: string (), a one-dimensional random simplified Chinese character string array of strlength characters ()

Static object [] createregioncode (INT strlength)
// This function randomly creates a hexadecimal byte array containing two elements within the Chinese character encoding range. Each byte array represents a Chinese character and stores four byte arrays in the object array.

Public static object [] createregioncode (INT strlength)
{
String [] strarray = new string [] {"0", "1", "2", "3", "4", "5", "6 ", "7", "8", "9", "A", "B", "C", "D", "E", "F "};
Random random = new random ();
Object [] objarray = new object [strlength];
For (INT I = 0; I <strlength; I ++)
{
Int num3;
Int num5;
Int Index = random. Next (11, 14 );
String STR = strarray [Index]. Trim ();
Random = new random (Index * (INT) datetime. Now. ticks) + I );
If (Index = 13)
{
Num3 = random. Next (0, 7 );
}
Else
{
Num3 = random. Next (0, 0x10 );
}
String str2 = strarray [num3]. Trim ();
Random = new random (num3 * (INT) datetime. Now. ticks) + I );
Int num4 = random. Next (10, 0x10 );
String str3 = strarray [num4]. Trim ();
Random = new random (num4 * (INT) datetime. Now. ticks) + I );
Switch (num4)
{
Case 10:
Num5 = random. Next (1, 0x10 );
Break;

Case 15:
Num5 = random. Next (0, 15 );
Break;

Default:
Num5 = random. Next (0, 0x10 );
Break;
}
String str4 = strarray [num5]. Trim ();
Byte num6 = convert. tobyte (STR + str2, 0x10 );
Byte num7 = convert. tobyte (str3 + str4, 0x10 );
Byte [] buffer = new byte [] {num6, num7 };
Objarray. setvalue (buffer, I );
}
Return objarray;
}

Public static string [] fonts (INT strlength)
{
Encoding encoding = encoding. getencoding ("gb2312 ");
Object [] objarray = createregioncode (strlength );
String [] strarray = new string [strlength];
For (INT I = 0; I <strlength; I ++)
{
Strarray [I] = encoding. getstring (byte []) convert. changetype (objarray [I], typeof (byte []);
}
Return strarray;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.