random GB2312 in python
2011-11-06 11:28
441 查看
""""
GB2312 http://zh.wikipedia.org/wiki/GB_2312
汉字区的“高位字节”的范围是0xB0-0xF7,“低位字节”的范围是0xA1-0xFE,
占用的码位是72*94=6768。其中有5个空位是D7FA-D7FE。
"""
def randomGB2312():
high=random.randint(0xB0, 0xF7)
if high==0xD7:
low=random.randint(0xA1, 0xF9)
else:
low=random.randint(0xA1, 0xFE)
val=(high<<8)+low
s='%x'%val
# print s
s2=s.decode('hex').decode('gb2312') #in contrary, hex(0xFE) returns hex string
return s2
for i in xrange(1000):
randomGB2312()
GB2312 http://zh.wikipedia.org/wiki/GB_2312
汉字区的“高位字节”的范围是0xB0-0xF7,“低位字节”的范围是0xA1-0xFE,
占用的码位是72*94=6768。其中有5个空位是D7FA-D7FE。
"""
def randomGB2312():
high=random.randint(0xB0, 0xF7)
if high==0xD7:
low=random.randint(0xA1, 0xF9)
else:
low=random.randint(0xA1, 0xFE)
val=(high<<8)+low
s='%x'%val
# print s
s2=s.decode('hex').decode('gb2312') #in contrary, hex(0xFE) returns hex string
return s2
for i in xrange(1000):
randomGB2312()
相关文章推荐
- get random number in python
- a_func_a_day_in_python_random随机函数
- Random Forests in Python
- urllib in Python 3
- Python顺序与range和random
- 深入理解Python中的__builtin__和__builtins__
- python解决SNIMissingWarning和InsecurePlatformWarning警告
- python的编码判断_unicode_gbk/gb2312_utf8(附函数)
- Chunked decoding in python
- [leetcode]Swap Nodes in Pairs @ Python
- python basic configuration in linux
- python - numpy.random 常用随机数
- 安装scipy或者numpy时弹出python2.7 was not found in the registry 的解决办法
- Python build-in function filter()
- SSLSocket passphrase/password in Python
- Embedding Python in Multi-Threaded C/C++ Applications
- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-b2PICB/unroll/
- python学习之random模块
- python启动失败 error: [Errno 98] Address already in use
- [leetcode, python] Reverse Words in a String 反转字符串