Tutorials Point


  Python Basics
  Python Advanced
  Python Useful References
  Python Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Python Number seed() Function


previous next AddThis Social Bookmark Button


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:

  • x: This is the seed for the next random number. If ommited then it takes system time to generate next random number.

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 Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names