GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.runoob.com — Python seed() 函数 | 菜鸟教程
Python 基础教程
Python 基础教程
Python 简介
Python 环境搭建
Python 中文编码
Python VS Code
Python 基础语法
Python 变量类型
Python 运算符
Python 条件语句
Python 循环语句
Python While 循环语句
Python for 循环语句
Python 循环嵌套
Python break 语句
Python continue 语句
Python pass 语句
Python Number(数字)
Python 字符串
Python 列表(List)
Python 元组
Python 字典(Dictionary)
Python 日期和时间
Python 函数
Python 模块
Python 文件I/O
Python File 方法
Python 异常处理
Python OS 文件/目录方法
Python 内置函数
Python 高级教程Python 面向对象 Python 正则表达式 Python CGI 编程 Python MySQL Python 网络编程 Python SMTP Python 多线程 Python XML 解析 Python GUI 编程(Tkinter) Python2.x 与 3.x 版本区别 Python IDE Python JSON Python AI 绘画 Python 100例 Python 测验Python seed() 函数描述seed() 方法改变随机数生成器的种子,可以在调用其他随机模块函数之前调用此函数。 语法以下是 seed() 方法的语法: import random random.seed ( [x] ) 我们调用 random.random() 生成随机数时,每一次生成的数都是随机的。但是,当我们预先使用 random.seed(x) 设定好种子之后,其中的 x 可以是任意数字,如10,这个时候,先调用它的情况下,使用 random() 生成的随机数将会是同一个。 注意:seed()是不能直接访问的,需要导入 random 模块,然后通过 random 静态对象调用该方法。 参数
返回值本函数没有返回值。 实例以下展示了使用 seed() 方法的实例: 实例
#!/usr/bin/python # -*- coding: UTF-8 -*- import random print random.random() print random.random() print "------- 设置种子 seed -------" random.seed( 10 ) print "Random number with seed 10 : ", random.random() # 生成同一个随机数 random.seed( 10 ) print "Random number with seed 10 : ", random.random() # 生成同一个随机数 random.seed( 10 ) print "Random number with seed 10 : ", random.random() 以上实例运行后输出结果为: 0.739880443211 0.78969784712 ------- 设置种子 seed ------- Random number with seed 10 : 0.57140259469 Random number with seed 10 : 0.57140259469 Random number with seed 10 : 0.57140259469
AI 思考中...
点我分享笔记取消
分类导航
Advertisement
|
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |