Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
681 views
in Technique[技术] by (71.8m points)

python - Does numpy.random.seed() always give the same random number every time?

I know that numpy.random.seed(seed) will output the same numbers if I use the same seed. My question is, does this change over time? If I try to call it again tomorrow, will it still output the same set of random numbers as yesterday?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...