As described in the documentation of pandas.DataFrame.sample, the random_state parameter accepts either an integer (as in your case) or a numpy.random.RandomState, which is a container for a Mersenne Twister pseudo random number generator.

If you pass it an integer, it will use this as a seed for a pseudo random number generator. As the name already says, the generator does not produce true randomness. It rather has an internal state (that you can get by calling np.random.get_state()) which is initialized based on a seed. When initialized by the same seed, it will reproduce the same sequence of "random numbers".

If you pass it a RandomState it will use this (already initialized/seeded) RandomState to generate pseudo random numbers. This also allows you to get reproducible results by setting a fixed seed when initializing the RandomState and then passing this RandomState around. Actually you should prefer this over setting the seed of numpys internal RandomState. The reasoning being explained in this answer by Robert Kern and the comments to it. The idea is to have an independent stream which prevents other parts of the program to mess up your reproducibility by changing the seed of numpys internal RandomState.

Answer from jotasi on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.sample.html
pandas.DataFrame.sample — pandas 3.0.5 documentation
Extract 3 random elements from the Series df['num_legs']: Note that we use random_state to ensure the reproducibility of the examples. >>> df["num_legs"].sample(n=3, random_state=1) fish 0 spider 8 falcon 2 Name: num_legs, dtype: int64
🌐
Scaler
scaler.com › home › topics › what is pandas dataframe sample() method?
What is Pandas DataFrame sample() Method? - Scaler Topics
May 4, 2023 - With the random_state argument ... a string ('index' or 'columns'). For the pandas dataframe, to sample random rows, we need to set this parameter to 0 or 'index', while to sample random columns – 1 or 'columns'....
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.DataFrame.sample.html
pandas.DataFrame.sample — pandas 3.0.4 documentation
Extract 3 random elements from the Series df['num_legs']: Note that we use random_state to ensure the reproducibility of the examples. >>> df["num_legs"].sample(n=3, random_state=1) fish 0 spider 8 falcon 2 Name: num_legs, dtype: int64
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: Random sampling from DataFrame with sample() | note.nkmk.me
May 22, 2022 - source: pandas_sample.py · The seed for the random number generator can be specified in the random_state parameter. The same rows/columns are returned for the same random_state.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-pandas-dataframe-sample
Pandas Dataframe.sample() | Python - GeeksforGeeks
July 11, 2025 - random_state: int value or numpy.random.RandomState, optional. if set to a particular integer, will return same rows as sample in every iteration. axis: 0 or 'row' for Rows and 1 or 'column' for Columns.
🌐
Sharp Sight
sharpsight.ai › blog › pandas-sample
Pandas Sample, Explained - Sharp Sight
July 24, 2021 - Then, we called the sample() method, also using dot syntax. Inside the parenthesis we set n = 5 and random_state = 33, which as you already learned, causes sample() to generate a random sample of a specific size (5 elements).
🌐
Pandas
pandas.pydata.org › docs › dev › reference › api › pandas.DataFrame.sample.html
pandas.DataFrame.sample — pandas documentation
Extract 3 random elements from the Series df['num_legs']: Note that we use random_state to ensure the reproducibility of the examples. >>> df["num_legs"].sample(n=3, random_state=1) fish 0 spider 8 falcon 2 Name: num_legs, dtype: int64
Find elsewhere
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 0.23.4 › generated › pandas.DataFrame.sample.html
pandas.DataFrame.sample — pandas 0.23.4 documentation
>>> df.sample(random_state=1) A B C D 37 -2.027662 0.103611 0.237496 -0.165867 43 -0.259323 -0.583426 1.516140 -0.479118 12 -1.686325 -0.579510 0.985195 -0.460286 8 1.167946 0.429082 1.215742 -1.636041 9 1.197475 -0.864188 1.554031 -1.505264
🌐
Vultr Docs
docs.vultr.com › python › third-party › pandas › DataFrame › sample
Python Pandas DataFrame sample() - Random Row or Column Selection | Vultr Docs
December 24, 2024 - Pass an integer to random_state which acts as the seed for the random number generator. ... # Sampling with a seed for reproducibility sample_seed = df.sample(n=2, random_state=1) print(sample_seed) Explain Code
🌐
Ryan Nolan Data
ryanandmattdatascience.com › home › python pandas › pandas sample
Pandas sample(): Random Sampling Made Simple in Python
June 15, 2025 - This line of code randomly selects 5 rows from the DataFrame df using a fixed random seed (11) to ensure the sample is retured every time it’s run · This line randomly selects 10% of the rows from the DataFrame df using random_state=11 to make the sampling reproducible.
🌐
W3Schools
w3schools.com › python › pandas › ref_df_sample.asp
Pandas DataFrame sample() Method
import pandas as pd df = pd.read_csv('data.csv') print(df.sample()) Try it Yourself » · The sample() method returns a specified number of random rows. The sample() method returns 1 row if a number is not specified.
🌐
w3resource
w3resource.com › pandas › series › series-sample.php
Pandas Series: sample() function - w3resource
May 13, 2026 - Example - Extract 3 random elements from the Series df['num_legs']: Note that we use random_state to ensure the reproducibility of the examples: Python-Pandas Code: import numpy as np import pandas as pd df = pd.DataFrame({'num_legs': [2, 4, 8, 0], 'num_wings': [2, 0, 0, 0], 'num_specimen_seen': [8, 2, 1, 6]}, index=['sparrow', 'cat', 'spider', 'snake']) df['num_legs'].sample(n=3, random_state=1) Output: snake 0 spider 8 sparrow 2 Name: num_legs, dtype: int64 ·
🌐
GitHub
github.com › pandas-dev › pandas › issues › 29221
df.sample random_state behavior across processes · Issue #29221 · pandas-dev/pandas
October 25, 2019 - I did manage to figure out that it can be solved by explicitly passing a new random state too sample().
Author   pandas-dev
🌐
w3resource
w3resource.com › pandas › dataframe › dataframe-sample.php
Pandas DataFrame: - sample() function - w3resource
August 19, 2022 - DataFrame.sample(self, n=None, frac=None, replace=False, weights=None, random_state=None, axis=None) Parameters: Returns: Series or DataFrame A new object of same type as caller containing n items randomly sampled from the caller object.
🌐
Spark Code Hub
sparkcodehub.com › pandas › data manipulation › sample
Mastering the sample Method in Pandas for Efficient Data ...
random_state: Integer or tuple for reproducible random sampling; ensures consistent results across runs. ... False (default), retains the original index. ... import pandas as pd # Sample DataFrame data = { 'product': ['Laptop', 'Phone', 'Tablet', ...
🌐
Skytowner
skytowner.com › explore › pandas_dataframe_sample_method
Pandas DataFrame | sample method with Examples
Whether or not to allow sampling from the same row. By default, replace=False. ... The weights assigned to the items. An item with high weight is more likely to be selected. If the weights do not sum up to 1, then they are normalised so that the sum becomes 1. By default, weights=None, which means that equal weights are assigned. 5. random_statelink | int or numpy.random.RandomState | optional