python random模块

python random模块

import random

print random.random()

print random.randint(1,2)

print random.randrange(1,10)

生成有机验证码

import random

checkcode = ''

for i in range(4):

    current = random.randrange(0,4)

    if current != i:

        temp = chr(random.randint(65,90))

    else:

        temp = random.randint(0,9)

    checkcode += str(temp)

print checkcode

你可能感兴趣的:(python random模块)