Python random.seed( ) method (original) (raw)

Last Updated : 14 Jan, 2026

The random.seed() method in Python is used to initialize the random number generator so that it produces the same sequence of random numbers every time a program is run. By setting a fixed seed value, randomness becomes reproducible, which is essential for debugging, testing and scientific experiments.

Let's understand with an example.

Python `

import random for i in range(2): print(random.randint(1, 1000))

for i in range(2): random.seed(0) print(random.randint(1, 1000))

`

Explanation: Notice that generating random numbers without using the .seed() method results in different outputs on each run, whereas using it ensures consistent results every time.

Syntax

random.seed(a=None, version=2)

Parameters

Return Type

random.seed() method does not return any value.

Let's look at some of the examples.

Reproducing Same Random Lists

We can produce the same random list for multiple executions using random.seed() method.

Python `

import random

random.seed(9) print(random.sample(range(1, 50), 6))

`

Output

[30, 40, 24, 18, 9, 12]

**Explanation:

Reproducible Data Splitting

In machine learning, we often split data into training and testing sets. Using a seed ensures that the split remains the same across multiple runs.

Python `

import random a = list(range(10)) random.seed(10) random.shuffle(a) print(a)

`

Output

[5, 2, 7, 1, 8, 4, 3, 6, 0, 9]

**Explanation: