Python基础入门之seed()方法的使用


Posted in Python onMay 15, 2015

 seed() 设置生成随机数用的整数起始值。调用任何其他random模块函数之前调用这个函数。
语法

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

seed ( [x] )

注意:此函数是无法直接访问的,所以需要导入seed模块,然后需要使用random静态对象来调用这个函数。
参数

  •     x -- 这是下一个随机数的种子。如果省略,则需要系统时间,以产生下一个随机数。

返回值

此方法不返回任何值。
例子

下面的例子显示了seed()方法的使用。

#!/usr/bin/python
import random

random.seed( 10 )
print "Random number with seed 10 : ", random.random()

# It will generate same random number
random.seed( 10 )
print "Random number with seed 10 : ", random.random()

# It will generate same random number
random.seed( 10 )
print "Random number with seed 10 : ", random.random()

当我们运行上面的程序,它会产生以下结果:

Random number with seed 10 : 0.57140259469
Random number with seed 10 : 0.57140259469
Random number with seed 10 : 0.57140259469
Python 相关文章推荐
Python中的Descriptor描述符学习教程
Jun 02 Python
基于python时间处理方法(详解)
Aug 14 Python
Python爬取十篇新闻统计TF-IDF
Jan 03 Python
python linecache 处理固定格式文本数据的方法
Jan 08 Python
详解pandas库pd.read_excel操作读取excel文件参数整理与实例
Feb 17 Python
python GUI图形化编程wxpython的使用
Jul 19 Python
简单了解python数组的基本操作
Nov 26 Python
python虚拟环境模块venv使用及示例
Mar 04 Python
Python xpath表达式如何实现数据处理
Jun 13 Python
python 动态绘制爱心的示例
Sep 27 Python
Scrapy 配置动态代理IP的实现
Sep 28 Python
使用Django框架创建项目
Jun 10 Python
Python中的random()方法的使用介绍
May 15 #Python
Python的randrange()方法使用教程
May 15 #Python
Python中的choice()方法使用详解
May 15 #Python
Python中利用sqrt()方法进行平方根计算的教程
May 15 #Python
简单介绍Python中的round()方法
May 15 #Python
Python入门之modf()方法的使用
May 15 #Python
简单介绍Python中用于求最小值的min()方法
May 15 #Python
You might like
解析php curl_setopt 函数的相关应用及介绍
2013/06/17 PHP
利用php+mcDropdown实现文件路径可在下拉框选择
2013/08/07 PHP
php文件缓存类汇总
2014/11/21 PHP
php去除字符串中空字符的常用方法小结
2015/03/17 PHP
Yii2 assets清除缓存的方法
2016/05/16 PHP
php模拟post上传图片实现代码
2016/06/24 PHP
微信自定义分享php代码分析
2016/11/24 PHP
PHP用户管理中常用接口调用实例及解析(含源码)
2017/03/09 PHP
Google Map API更新实现用户自定义标注坐标
2009/07/29 Javascript
javascript中判断一个值是否在数组中并没有直接使用
2012/12/17 Javascript
javascript中match函数的用法小结
2014/02/08 Javascript
jQuery模拟新浪微博首页滚动效果的方法
2015/03/11 Javascript
jQuery实现动态添加和删除一个div
2015/08/12 Javascript
JS访问DOM节点方法详解
2016/11/29 Javascript
nodejs基于WS模块实现WebSocket聊天功能的方法
2018/01/12 NodeJs
node下使用UglifyJS压缩合并JS文件的方法
2018/03/07 Javascript
Bootstrap开发中Tab标签页切换图表显示问题的解决方法
2018/07/13 Javascript
JavaScript选择排序算法原理与实现方法示例
2018/08/06 Javascript
使用vue点击li,获取当前点击li父辈元素的属性值方法
2018/09/12 Javascript
JS 正则表达式验证密码、邮箱格式的实例代码
2018/10/28 Javascript
Vue如何实现变量表达式选择器
2021/02/18 Vue.js
Python linecache.getline()读取文件中特定一行的脚本
2008/09/06 Python
在Django的session中使用User对象的方法
2015/07/23 Python
Python 判断文件或目录是否存在的实例代码
2018/07/19 Python
Python实现滑动平均(Moving Average)的例子
2019/08/24 Python
浅谈tensorflow 中tf.concat()的使用
2020/02/07 Python
关于PySnooper 永远不要使用print进行调试的问题
2021/03/04 Python
俄罗斯汽车零件和配件在线商店:CarvilleShop
2019/11/29 全球购物
华硕新加坡官方网上商店:ASUS Singapore
2020/07/09 全球购物
自我评价200字分享
2013/12/17 职场文书
函授大学生自我鉴定
2014/02/05 职场文书
2014幼儿园大班工作总结
2014/11/10 职场文书
暑假生活随笔
2015/08/15 职场文书
《平移和旋转》教学反思
2016/02/19 职场文书
JavaScript 实现页面滚动动画
2021/04/24 Javascript
Python机器学习之底层实现KNN
2021/06/20 Python