Generate random Chinese character in Python

This is a python script that can be used to generate random Chinese characters. Funny script!

#!/usr/bin/python
import random
def rand_ch_ch():
    head = random.randint(0xB0, 0xDF)
    body = random.randint(0xA, 0xF)
    tail = random.randint(0, 0xF)
    val = ( head << 0x8 ) | (body << 0x4 ) | tail
    str = "%x" % val
    return str.decode('hex').decode('gb2312')

Not sure where it is originally from. If you’re the creator, please let me know.

Share Button

Leave a comment

Your email address will not be published. Required fields are marked *