Python random number generator
The following example demonstrates how to generate a random number:
# -*- coding: UTF-8 -*- # Filename : test.py # author by : www.w3big.com # 生成 0 ~ 9 之间的随机数 # 导入 random(随机数) 模块 import random print(random.randint(0,9))
Execute the above code output results:
4
The above examples we used randint random module () function to generate random numbers, return different numbers (0-9) after every time you do, the syntax of the function is:
random.randint(a,b)
Function returns the number N, N being numbers between a to b (a <= N <= b), contains a and b.