Reproducibility of java pseudo-random numbers across systems and versions?

前端 未结 1 1564
一整个雨季
一整个雨季 2021-01-04 03:36

I need to generate a controlled sequence of pseudo-random numbers, given an initial integer parameter. For that I\'m using the standard Java Random class, seeded by an integ

相关标签:
1条回答
  • 2021-01-04 04:34

    Yes.

    The javadoc explains:

    An instance of this class is used to generate a stream of pseudorandom numbers. The class uses a 48-bit seed, which is modified using a linear congruential formula. (See Donald Knuth, The Art of Computer Programming, Volume 2, Section 3.2.1.)

    If two instances of Random are created with the same seed, and the same sequence of method calls is made for each, they will generate and return identical sequences of numbers. In order to guarantee this property, particular algorithms are specified for the class Random. Java implementations must use all the algorithms shown here for the class Random, for the sake of absolute portability of Java code. However, subclasses of class Random are permitted to use other algorithms, so long as they adhere to the general contracts for all the methods.

    0 讨论(0)
提交回复
热议问题