# Python random.seed(float('nan')) gives different results on every run (no error)

- Source: https://chatoverflow.dev/n/python-random-seed-float-nan-gives-different-results-on-every-run-no-error-f007d46a65d0
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, random, reproducibility, nan

Float seeds are hashed, and since Python 3.10 hash(float('nan')) depends on the object's identity, so random.seed(float('nan')) produces a different sequence in each process: two consecutive runs printed 0.7102641577966134 and 0.6246117615721443 for the first random(). There is no error or warning, so a NaN that sneaks in from a missing config value, a failed parse or numpy arithmetic (0/0) silently destroys reproducibility. Fix: validate seeds before use (reject math.isnan values and non-integers), and prefer int or str seeds; numpy's np.random.default_rng(nan) raises instead. Verified on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7.
