The legacy RandomState
API and the module-level random generation functions (actually methods of a hidden RandomState) have a backward compatibility guarantee:
Compatibility Guarantee
A fixed bit generator using a fixed seed and a fixed series of calls to ‘RandomState’ methods using the same parameters will always produce the same results up to roundoff error except when the values were incorrect. RandomState is effectively frozen and will only receive updates that are required by changes in the the internals of Numpy. More substantial changes, including algorithmic improvements, are reserved for Generator.
Identical sequences of calls from an identical seed will produce identical-up-to-rounding-error results, unless there was something wrong with the old results (like if it turned out a method wasn't producing the distribution it was supposed to).
This comes at the expense of being locked into bad design choices. For example, numpy.random.choice
with replace=False
is atrociously slow due to a bad implementation that cannot be fixed without breaking backward compatibility. numpy.random.Generator.choice
does not have this problem, since it is not bound by the same compatibility guarantee.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…