logo

Python Number Seed() Method


Show

Description

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.

Syntax

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.

Parameters

  • x - This is the seed for the next random number. In case omitted, then it takes system time for generating the next random number.

Return Value

This method in random number functions of Python does not return any value.

Example

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.