Declare internal state of PRNGs as fields
This commit is contained in:
parent
be6a353bec
commit
f31a38c307
@ -4,7 +4,7 @@ kotlin.code.style=official
|
|||||||
specifyKotlinAsDependency=false
|
specifyKotlinAsDependency=false
|
||||||
|
|
||||||
projectGroup=ru.dbotthepony.kommons
|
projectGroup=ru.dbotthepony.kommons
|
||||||
projectVersion=3.3.1
|
projectVersion=3.3.2
|
||||||
|
|
||||||
guavaDepVersion=33.0.0
|
guavaDepVersion=33.0.0
|
||||||
gsonDepVersion=2.8.9
|
gsonDepVersion=2.8.9
|
||||||
|
@ -11,7 +11,10 @@ import java.util.random.RandomGenerator
|
|||||||
* Generally shouldn't be used, and instead [PCG32Random] should be used, considering the latter has same memory
|
* Generally shouldn't be used, and instead [PCG32Random] should be used, considering the latter has same memory
|
||||||
* requirements but has way better statistical properties.
|
* requirements but has way better statistical properties.
|
||||||
*/
|
*/
|
||||||
open class LCG64Random(protected var seed: Long) : RandomGenerator {
|
open class LCG64Random(
|
||||||
|
@JvmField
|
||||||
|
protected var seed: Long
|
||||||
|
) : RandomGenerator {
|
||||||
override fun nextLong(): Long {
|
override fun nextLong(): Long {
|
||||||
val a = nextInt().toLong()
|
val a = nextInt().toLong()
|
||||||
val b = nextInt().toLong() and 0xFFFFFFFFL
|
val b = nextInt().toLong() and 0xFFFFFFFFL
|
||||||
|
@ -6,7 +6,10 @@ import java.util.random.RandomGenerator
|
|||||||
* PCG XSH RR 32-bit (64-bit state) random generator, which has way better statistical properties
|
* PCG XSH RR 32-bit (64-bit state) random generator, which has way better statistical properties
|
||||||
* than plain [LCG64Random] generator
|
* than plain [LCG64Random] generator
|
||||||
*/
|
*/
|
||||||
open class PCG32Random(protected var seed: Long) : RandomGenerator {
|
open class PCG32Random(
|
||||||
|
@JvmField
|
||||||
|
protected var seed: Long
|
||||||
|
) : RandomGenerator {
|
||||||
final override fun nextInt(): Int {
|
final override fun nextInt(): Int {
|
||||||
var x = this.seed
|
var x = this.seed
|
||||||
this.seed = LCG64Random.MULTIPLIER * this.seed + LCG64Random.INCREMENT
|
this.seed = LCG64Random.MULTIPLIER * this.seed + LCG64Random.INCREMENT
|
||||||
|
@ -8,9 +8,13 @@ import java.util.random.RandomGenerator
|
|||||||
* Where [Xoshiro256PlusPlusRandom] is used consider using [Xoshiro256StarStarRandom] instead.
|
* Where [Xoshiro256PlusPlusRandom] is used consider using [Xoshiro256StarStarRandom] instead.
|
||||||
*/
|
*/
|
||||||
open class Xoshiro256PlusPlusRandom protected constructor(
|
open class Xoshiro256PlusPlusRandom protected constructor(
|
||||||
|
@JvmField
|
||||||
protected var s0: Long,
|
protected var s0: Long,
|
||||||
|
@JvmField
|
||||||
protected var s1: Long,
|
protected var s1: Long,
|
||||||
|
@JvmField
|
||||||
protected var s2: Long,
|
protected var s2: Long,
|
||||||
|
@JvmField
|
||||||
protected var s3: Long,
|
protected var s3: Long,
|
||||||
mark: Nothing?
|
mark: Nothing?
|
||||||
) : RandomGenerator {
|
) : RandomGenerator {
|
||||||
|
@ -8,9 +8,13 @@ import java.util.random.RandomGenerator
|
|||||||
* by backward compatibility)
|
* by backward compatibility)
|
||||||
*/
|
*/
|
||||||
open class Xoshiro256StarStarRandom protected constructor(
|
open class Xoshiro256StarStarRandom protected constructor(
|
||||||
|
@JvmField
|
||||||
protected var s0: Long,
|
protected var s0: Long,
|
||||||
|
@JvmField
|
||||||
protected var s1: Long,
|
protected var s1: Long,
|
||||||
|
@JvmField
|
||||||
protected var s2: Long,
|
protected var s2: Long,
|
||||||
|
@JvmField
|
||||||
protected var s3: Long,
|
protected var s3: Long,
|
||||||
mark: Nothing?
|
mark: Nothing?
|
||||||
) : RandomGenerator {
|
) : RandomGenerator {
|
||||||
|
Loading…
Reference in New Issue
Block a user