Python random() 函数

Python 教程 · 2019-02-02 05:58:20

描述

random() 方法返回随机生成的一个实数,它在[0,1)范围内。

语法

以下是 random() 方法的语法:

import random

random.random()

注意:random()是不能直接访问的,需要导入 random 模块,然后通过 random 静态对象调用该方法。

参数

返回值

返回随机生成的一个实数,它在[0,1)范围内。

实例

以下展示了使用 random() 方法的实例:

#!/usr/bin/python
import random

# 生成第一个随机数
print "random() : ", random.random()

# 生成第二个随机数
print "random() : ", random.random()

以上实例运行后输出结果为:

random() :  0.281954791393
random() :  0.309090465205

点击查看所有 Python 教程 文章: https://codercto.com/courses/l/8.html

查看所有标签

Large-Scale Inference

Large-Scale Inference

Bradley Efron / Cambridge University Press / 2010-8-5 / GBP 48.00

We live in a new age for statistical inference, where modern scientific technology such as microarrays and fMRI machines routinely produce thousands and sometimes millions of parallel data sets, each ......一起来看看 《Large-Scale Inference》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换