Copyright © tutorialspoint.com
This function sets the integer starting value used in generating random numbers. Call this function before calling any other random module function.
seed ( [x] ) |
Note: This function is not accessible directly so we need to import seed module and then we need to call this function using random static object.
Here is the detail of parameters:
x: This is the seed for the next random number. If ommited then it takes system time to generate next random number.
Returns None.
#!/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() |
This will produce following result:
Random number with seed 10 : 0.57140259469 Random number with seed 10 : 0.57140259469 Random number with seed 10 : 0.57140259469 |
Copyright © tutorialspoint.com