diff --git a/gradle.properties b/gradle.properties index a62a894..4557ed5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ kotlin.code.style=official specifyKotlinAsDependency=false projectGroup=ru.dbotthepony.kommons -projectVersion=3.4.0 +projectVersion=3.5.0 guavaDepVersion=33.0.0 gsonDepVersion=2.8.9 diff --git a/src/main/kotlin/ru/dbotthepony/kommons/random/GJRAND64Random.kt b/src/main/kotlin/ru/dbotthepony/kommons/random/GJRAND64Random.kt new file mode 100644 index 0000000..b55c7a6 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kommons/random/GJRAND64Random.kt @@ -0,0 +1,41 @@ +package ru.dbotthepony.kommons.random + +import java.util.random.RandomGenerator + +/** + * From [gjrand website](https://gjrand.sourceforge.net): + * + * The gjrand project is about pseudo-random number generation for the purpose of simulations, + * Monte-Carlo integration, computer games and the like. It is intended that statistical + * properties be extremely good for such purposes. However, gjrand is not suitable as a + * high security random number generator for cryptography, the state lottery draw, etc. + */ +open class GJRAND64Random protected constructor( + @JvmField + protected var s0: Long, + @JvmField + protected var s1: Long, + @JvmField + protected var s2: Long, + @JvmField + protected var s3: Long, + marker: Nothing? +) : RandomGenerator { + constructor(seed0: Long, seed1: Long) : this(seed0, seed1, 2000001L, 0L, null) + constructor(seed: Long) : this(seed, 0L) + + final override fun nextLong(): Long { + s1 += s2 + s0 = s0.rotateLeft(32) + s2 = s2 xor s1 + s3 += 0x55aa96a5L + s0 += s1 + s2 = s2.rotateLeft(23) + s1 = s1 xor s0 + s0 += s2 + s1 = s1.rotateLeft(19) + s2 += s0 + s1 += s3 + return s0 + } +}