How to use the seed() method in Python? The following is a relevant introduction to the seed() method:
Description
The seed() method changes the seed of the random number generator. This function can be called before calling other random module functions.
Syntax
The following is the syntax of the seed() method:
import random random.seed ( [x] )
Note: seed() cannot be accessed directly and needs to import the random module , and then call this method through the random static object.
Related recommendations: "Python Video Tutorial"
Parameters
x -- Change the seed of the random number generator . If you don't understand the principle, you don't have to set the seed specifically, Python will choose the seed for you.
Return value
This function has no return value.
Example
The following shows an example of using the seed() method:
#!/usr/bin/python # -*- coding: UTF-8 -*- 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()
The output result after running the above example is:
Random number with seed 10 : 0.57140259469 Random number with seed 10 : 0.57140259469 Random number with seed 10 : 0.57140259469
The above is the detailed content of How to use the seed() method in Python. For more information, please follow other related articles on the PHP Chinese website!