python随机数seed用法

import random
...

def main():
    a = random.Random()
    a.seed(1)
    print a.random()

这样就可以通过种子取得固定随机值了

网上很多只写了一半,导致用random.seend(..)调用总报错。。

时间: 2024-08-07 08:35:00

python随机数seed用法的相关文章

python   __name__=='__main__' 用法

python 文件的后缀为.py,比如 name.py python 文件可以直接执行,也可以被导入.调用,比如import name; script 1: #!/bin/python # Filename:name.py if __name__=='__main__':     print 'This program is being run by itself' else:     print 'I am being imported from another module' script

python之函数用法capitalize()

# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法capitalize() #capitalize() #说明:将字符串的第一个字母变成大写,其他字母变小写. ''' capitalize(...) S.capitalize() -> string Return a copy of the string S with only its first character capitalized. ''' #案例 str='xiaoden

python之函数用法setdefault()

# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法setdefault() #D.get(k,d) #说明:k在D中,则返回 D[K],如果k不在D中,则返回d值 #D.get(k,d), also set D[k]=d if k not in D ''' >>> help(dict.setdefault) Help on built-in function setdefault: setdefault(...) D.set

python之函数用法islower()

# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法islower() #http://www.runoob.com/python/att-string-islower.html #islower() #说明:检测字符串是否都由小写字母组成 str = "THIS is string example....wow!!!" print str.islower()#False str = "this is string

python之函数用法xrange()

# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法xrange() #xrange() #说明:返回一个生成器 #xrange做循环的性能比range好,尤其是返回很大的时候.除非要返回一个列表,则用range. ''' class xrange(object) | xrange(stop) -> xrange object | xrange(start, stop[, step]) -> xrange object | | Li

python之函数用法startswith()

# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法startswith() #http://www.runoob.com/python/att-string-startswith.html #startswith() #说明:返回布尔值,用于检查字符串是否是以指定子字符串开头,如果是则返回 True,否则返回 False. ''' startswith(...) S.startswith(prefix[, start[, end]]

python之函数用法globals()

# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法globals() #globals() #说明:在当前作用域下,查看全局变量 ''' globals(...) globals() -> dictionary Return the dictionary containing the current scope's global variables. ''' #案例 b='xiaodeng' print globals#<buil

python之函数用法__setattr__

# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法__setattr__ #http://www.cnblogs.com/hongfei/p/3858256.html #用__setattr__函数重构方法 class Fruit(): def __init__(self,color,price): self.__color = color self.__price = price def __setattr__(self,name

objective-c 中随机数的用法 (3种:arc4random() 、random()、CCRANDOM_0_1() )

1.随机数的使用      1).arc4random() 比较精确不需要生成随即种子 使用方法 : 通过arc4random() 获取0到x-1之间的整数的代码如下: int value = arc4random() % x; 获取1到x之间的整数的代码如下: int value = (arc4random() % x) + 1; 2).CCRANDOM_0_1() cocos2d中使用 ,范围是[0,1] 使用方法: float random = CCRANDOM_0_1() * 5; //