NotePublic/Software/Development/Language/Python/Python_随机数生成.md

26 lines
573 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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。