Latest web development tutorials

Python seed () function

Python figures Python figures


description

seed () method to change the random number generator seed, you can call this function before calling other random module functions..


grammar

The following is the syntax seed () method:

import random

random.seed ( [x] )

Note: seed (() is not directly accessible, you need to import the random module, and then call the method by random static objects.


parameter

  • x - change random number generator seed seed. If you do not understand the principle, you do not have to set special seed, Python will help you choose the seed.

return value

This function does not return a value.


Examples

The following illustrates the use of seed (() method Example:

#!/usr/bin/python
import random

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()

After running the above example output is:

Random number with seed 10 :  0.57140259469
Random number with seed 10 :  0.57140259469
Random number with seed 10 :  0.57140259469

Python figures Python figures