Copyright © tutorialspoint.com

Python Number seed() Function

previous next


Description:

This function sets the integer starting value used in generating random numbers. Call this function before calling any other random module function.

Syntax:

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.

Parameters:

Here is the detail of parameters:

Return Value:

Returns None.

Example:

#!/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

previous next

Copyright © tutorialspoint.com