File tree Expand file tree Collapse file tree 2 files changed +37
-4
lines changed
Expand file tree Collapse file tree 2 files changed +37
-4
lines changed Original file line number Diff line number Diff line change 177177 "lastOpenFiles" : [
178178 " C++ CSP-J/数据类型.md" ,
179179 " C++ CSP-J/C++ 之 CSP-J 主要内容.md" ,
180+ " src/25.常用内建模块/random.md" ,
181+ " src/25.常用内建模块/内建模块.md" ,
182+ " src/18.内置函数/内置函数.md" ,
183+ " src/16.推导式与函数/推导式与函数.md" ,
184+ " src/04.运算符和表达式/运算符和表达式.md" ,
185+ " src/03.类型和变量/类型和变量.md" ,
186+ " src/11.字符串/字符串.md" ,
187+ " src/25.常用内建模块/math.md" ,
180188 " C++ CSP-J" ,
181189 " Untitled.canvas" ,
182- " src/25.常用内建模块/内建模块.md" ,
183190 " src/SUMMARY.md" ,
184191 " README.md" ,
185192 " (25.常用内建模块/常用内建模块.md" ,
186193 " src/25.常用内建模块/time.md" ,
187- " src/25.常用内建模块/math.md" ,
188194 " (25.常用内建模块" ,
189195 " src/introduction.md" ,
190196 " src/08.选择结构/三大结构.md" ,
191- " src/03.类型和变量/类型和变量.md" ,
192197 " src/05.位运算/位运算.md" ,
193198 " src/24.自定义函数/User-Defined Function.md" ,
194199 " src/24.自定义函数" ,
195200 " src/07.海龟画图/海龟画图一.md" ,
196201 " src/附录/appendix.md" ,
197- " src/04.运算符和表达式/运算符和表达式.md" ,
198202 " src/25.常用内建模块" ,
199203 " src/22.排序算法/排序算法.md" ,
200204 " src/23.二分法查找/二分法查找.md"
Original file line number Diff line number Diff line change 1+
2+ ` Python ` 的` random ` 模块用于生成伪随机数以及执行随机操作,它提供了多种方法可以处理随机数、随机选择、打乱序列。
3+
4+ ## 1. 生成随机数
5+
6+ ### 随机浮点数
7+
8+ - ** ` random() ` ** : 生成一个` 0 ` 到` 1 ` 之间的随机浮点数(左闭右开区间)
9+ ``` python
10+ >> > import random as r
11+ >> > print (r.random())
12+ ```
13+
14+ - ** uniform(a, b)** : 生成一个范围在` [a, b] ` 的随机浮点数
15+ ``` python
16+ >> > print (r.uniform(10 , 20 ))
17+ ```
18+
19+ ### 随机整数
20+
21+ - ** randint(a, b)** : 生成一个范围在` [a, b] ` 的随机整数
22+ ``` python
23+ >> > print (r.randint(1 , 10 ))
24+ ```
25+
26+ - ** randrange(start, stop, step)** : 从指定的范围内,按步长返回一个随机整数
27+ ``` python
28+ >> > print (r.randrange(1 , 10 , 2 ))
29+ ```
You can’t perform that action at this time.
0 commit comments