From 2be2c2b2958e965b4ad2bca713c03dfe87fa84d5 Mon Sep 17 00:00:00 2001 From: "rick.chan" Date: Wed, 9 Sep 2020 14:57:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Python=20=E9=9A=8F?= =?UTF-8?q?=E6=9C=BA=E6=95=B0=E7=94=9F=E6=88=90.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: rick.chan --- .../Language/Python/Python_随机数生成.md | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Software/Development/Language/Python/Python_随机数生成.md diff --git a/Software/Development/Language/Python/Python_随机数生成.md b/Software/Development/Language/Python/Python_随机数生成.md new file mode 100644 index 0000000..cc45375 --- /dev/null +++ b/Software/Development/Language/Python/Python_随机数生成.md @@ -0,0 +1,25 @@ +# Python 随机数生成 + +以下实例演示了如何生成一个随机数: + +```python +# -*- coding: UTF-8 -*- + +# Filename : test.py +# author by : www.runoob.com + +# 生成 0 ~ 9 之间的随机数 + +# 导入 random(随机数) 模块 +import random + +print(random.randint(0,9)) +``` + +以上实例我们使用了 random 模块的 randint() 函数来生成随机数,你每次执行后都返回不同的数字(0 到 9),该函数的语法为: + +```python +random.randint(a,b) +``` + +函数返回数字 N ,N 为 a 到 b 之间的数字(a <= N <= b),包含 a 和 b。