Easy Tutorial
❮ Python Mysql Connector Pyhton Remove Ith Character From String ❯

Python3 seed() Function

Python3 Numbers


Description

The seed() method changes the seed of the random number generator, which can be called before invoking other random module functions.


Syntax

Here is the syntax for the seed() method:

import random

random.seed([x])

When we call random.random() to generate random numbers, each number generated is random. However, if we pre-set the seed using random.seed(x) where x can be any number, such as 10, the random numbers generated using random() will be the same when called after setting the seed.

Note: The seed() method cannot be accessed directly. It requires importing the random module and then calling the method through the random static object.


Parameters


Return Value

This function does not return any value.


Example

The following demonstrates the use of the seed() method:

#!/usr/bin/python3
import random

random.seed()
print("Generating random number using default seed:", random.random())
print("Generating random number using default seed:", random.random())

random.seed(10)
print("Generating random number using integer 10 as seed:", random.random())
random.seed(10)
print("Generating random number using integer 10 as seed:", random.random())

random.seed("hello", 2)
print("Generating random number using string as seed:", random.random())

The output of the above example is:

Generating random number using default seed: 0.7908102856355441
Generating random number using default seed: 0.81038961519195
Generating random number using integer 10 as seed: 0.5714025946899135
Generating random number using integer 10 as seed: 0.5714025946899135
Generating random number using string as seed: 0.3537754404730722

Python3 Numbers

❮ Python Mysql Connector Pyhton Remove Ith Character From String ❯