Random Stochastic module
>>> Import Random Importing module
>>> random.random () randomly generates a floating-point number
0.30851751369227465
>>> Random.randrange (6) randomly generate 0-5 of the numbers
2
>>> random.choice (' ABCDEFG ') randomly generates a single letter
C
>>> random.sample (xrange (100), 3) do not repeat randomly extract three
[62, 78, 28]
[email protected] ~]# cat checkcode.py
#!/usr/bin/env python
#-*-Coding:utf-8-*-
#随机生成6位验证码
Import Random
Checkcode = ' '
For I in range (6):
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
[email protected] ~]# python checkcode.py
Fmb1oy
[email protected] ~]# python checkcode.py
0FNKVR
This article is from "Kaka West" blog, please be sure to keep this source http://whnba.blog.51cto.com/1215711/1725206
Built-in modules: random