Python3 random() 函数

Python 3 教程 · 2019-02-05 15:44:13

描述

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

语法

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

import random

random.random()

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

参数

返回值

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

实例

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

#!/usr/bin/python3
import random

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

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

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

random() :  0.09690599908884856
random() :  0.8732120512570916

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

查看所有标签

Introduction to the Design and Analysis of Algorithms

Introduction to the Design and Analysis of Algorithms

Anany Levitin / Addison Wesley / 2011-10-10 / USD 117.00

Based on a new classification of algorithm design techniques and a clear delineation of analysis methods, Introduction to the Design and Analysis of Algorithms presents the subject in a coherent a......一起来看看 《Introduction to the Design and Analysis of Algorithms》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

URL 编码/解码
URL 编码/解码

URL 编码/解码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具