Python随机生成数模块random使用实例

WBOY
Release: 2016-06-10 15:15:28
Original
1463 people have browsed it

代码

复制代码 代码如下:

#!/usr/bin/env python
#coding=utf-8
import random

#生成[0, 1)直接随机浮点数
print random.random()

#[x, y]中的随机整数
print random.randint(1, 100)

list = [1, 2, 3, 4, 5]
#随机选取
print random.choice(list)

#随机打乱
random.shuffle(list)
print list


输出
复制代码 代码如下:

0.787074152336
95
1
[4, 5, 2, 3, 1]
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template