生成漢字:
第一種方法:unicode碼
在unicode碼中,漢字的範圍是(0x4e00, 9fbf)
import
random
def
unicode
():
val
=
random.randint(
0x4e00
,
0x9fbf
)
return
chr
(val)
這個方法比較簡單,但是有個小問題,unicode碼中收錄了2萬多個漢字,包含很多生僻的繁體字.
第二種方法:gbk2312
gbk2312對字元的編碼採用兩個位元組相組合,第乙個位元組的範圍是0xb0-0xf7, 第二個位元組的範圍是0xa1-0xfe.
對gbk2312編碼方式詳細的解釋請參看gbk2312編碼
import
random
def
gbk2312():
head
=
random.randint(
0xb0
,
0xf7
)
body
=
random.randint(
0xa1
,
0xfe
)
val
=
f
''
str
=
bytes.fromhex(val).decode(
'gb2312'
)
return
str
gbk2312收錄了6千多常用漢字
生成英文本母:
import randoms = random.randint(65,90)
r=chr(s)
print(r)
隨機生成漢字!
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...
生成隨機漢字
using system using system.text 此函式在漢字編碼範圍內隨機建立含兩個元素的十六進製制位元組陣列,每個位元組陣列代表乙個漢字,並將 四個位元組陣列儲存在object陣列中。引數 strlength,代表需要產生的漢字個數 public static object crea...
python 隨機生成漢字 數字
在unicode碼中,漢字的範圍是 0x4e00,9fbf 這個方法比較簡單,但是有個小問題,unicode碼中收錄了2萬多個漢字,包含很多生僻的繁體字.gbk2312對字元的編碼採用兩個位元組相組合,第乙個位元組的範圍是0xb0 0xf7,第二個位元組的範圍是0xa1 0xfe.對gbk2312編...