Getting started with Python using the seed () method
This article describes how to use the seed () method in basic Python basics. It is the basic knowledge of Python learning. For more information, see
Seed () is used to set the start value of the integer used to generate a random number. Call this function before calling any other functions of the random module.
Syntax
The syntax of the seed () method is as follows:
?
Note: This function cannot be directly accessed. Therefore, you need to import the seed module and then use the random static object to call this function.
Parameters
- X -- this is the seed of the next random number. If this parameter is omitted, the system time is required to generate the next random number.
Return Value
This method does not return any value.
Example
The following example shows how to use the seed () method.
?
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#! /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 will produce the following results:
?
1 2 3 |
Random number with seed 10: 0.57140259469 Random number with seed 10: 0.57140259469 Random number with seed 10: 0.57140259469 |