A data split or a NumPy generator is made without a seed, so results differ between runs

tx0/python:unseeded-randomnessstrictnotemaintainability/designdepth fastmaintainability

What it finds

train_test_split without random_state and numpy.random.default_rng() without a seed take fresh entropy each run, so a model trained or a sample drawn cannot be reproduced. A fixed seed, or one passed in, makes runs repeatable. A split with shuffle given is left alone.

From the rule's source, unseeded_randomness.rs.

Example from the rule's tests
import numpy as npfrom sklearn.model_selection import train_test_split rng = np.random.default_rng()tx0 reports: without a seed this gives different resultsseeded = np.random.default_rng(42) def split(x, y):    a = train_test_split(x, y, test_size=0.2)tx0 reports: without a seed    b = train_test_split(x, y, random_state=0)    c = train_test_split(x, y, shuffle=False)    return a, b, c
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/python:unseeded-randomness" = "note"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:unseeded-randomness] reason="..."

tx0 explain tx0/python:unseeded-randomness shows the same in the terminal. Found a false positive? Report it.