The seed() method in Python number sets the starting integer value which is used for generating random numbers. One must call this function prior to calling any other random module function. The seed() method in the Python random module initializes the pseudo-random number generator. In case you make use of the same seed for initializing, then the random output would remain the same.
Here is the syntax for seed() method:
seed ( [x] )
Note - One cannot access this function directly, so it is required to import the random module in Python, and then we are supposed to call this function making use of the random static object.
This method in random number functions of Python does not return any value.
The example below shows the usage of seed() method.
#!/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()
When we run the above program, it produces the following result:
Random number with seed 10 : 0.57140259469 Random number with seed 10 : 0.57140259469 Random number with seed 10 : 0.57140259469
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.