生成隨機漢字

2021-06-21 01:50:30 字數 1301 閱讀 9364

using system;

using system.text;

/**/

/* 此函式在漢字編碼範圍內隨機建立含兩個元素的十六進製制位元組陣列,每個位元組陣列代表乙個漢字,並將

四個位元組陣列儲存在object陣列中。

引數:strlength,代表需要產生的漢字個數

*/ public static object createregioncode(int strlength)

;random rnd = new random();

//定義乙個object陣列用來

object bytes = new object[strlength];

/**/

/*每迴圈一次產生乙個含兩個元素的十六進製制位元組陣列,並將其放入bject陣列中

每個漢字有四個區位碼組成

區位碼第1位和區位碼第2位作為位元組陣列第乙個元素

區位碼第3位和區位碼第4位作為位元組陣列第二個元素

*/ for (int i = 0; i < strlength; i++)

else

string str_r2 = rbase[r2].trim();

//區位碼第3位

rnd = new random(r2 * unchecked((int) datetime.now.ticks) + i);

int r3 = rnd.next(10, 16);

string str_r3 = rbase[r3].trim();

//區位碼第4位

rnd = new random(r3 * unchecked((int) datetime.now.ticks) + i);

int r4;

if (r3 == 10)

else if (r3 == 15)

else

string str_r4 = rbase[r4].trim();

//定義兩個位元組變數儲存產生的隨機漢字區位碼

byte byte1 = convert.tobyte(str_r1 + str_r2, 16);

byte byte2 = convert.tobyte(str_r3 + str_r4, 16);

//將兩個位元組變數儲存在位元組陣列中

byte str_r = new byte ;

//將產生的乙個漢字的位元組陣列放入object陣列中

bytes.setvalue(str_r, i);

}return bytes;}}

}

隨機生成漢字!

var aa string bb array 1.95 of byte cc array 1.95 of byte i,j integer begin i a0 for j 1 to 95 do begin bb j i cc j i inc i end randomize for i 1 to 3...

Java 生成隨機漢字名稱

方法一 class randomhan 這種會有繁體字。class randomhan han的使用可以自己設定很多預選漢字,然後通過中文轉unicode 轉碼 或者直接設定 乙個string 漢字陣列,然後隨機取字。public string getchinese long seed throws...

jmeter生成隨機漢字,隨機ip位址

public class random str catch unsupportedencodingexception ex ret str return ret 測試 random str ran newrandom str string content1 新增 ran.randomjianhan ...