This article describes how to use the seed () method in basic Python basics. It is the basic knowledge of Python learning. For more information, see seed () set the start value of the integer used to generate a random number. Call this function before calling any other functions of the random module.
Syntax
The syntax of the seed () method is as follows:
seed ( [x] )
Note: This function cannot be directly accessed. Therefore, you need to import the seed module and then use the random static object to call this function.
Parameters
- X -- this is the seed of the next random number. If this parameter is omitted, the system time is required to generate the next random number.
Return Value
This method does not return any value.
Example
The following example shows how to use the seed () method.
#!/usr/bin/pythonimport randomrandom.seed( 10 )print "Random number with seed 10 : ", random.random()# It will generate same random numberrandom.seed( 10 )print "Random number with seed 10 : ", random.random()# It will generate same random numberrandom.seed( 10 )print "Random number with seed 10 : ", random.random()
When we run the above program, it will produce the following results:
Random number with seed 10 : 0.57140259469Random number with seed 10 : 0.57140259469Random number with seed 10 : 0.57140259469