Un-final properties and methods of random generators
This commit is contained in:
parent
5bd1717636
commit
ed8a5edcda
@ -4,7 +4,7 @@ kotlin.code.style=official
|
|||||||
specifyKotlinAsDependency=false
|
specifyKotlinAsDependency=false
|
||||||
|
|
||||||
projectGroup=ru.dbotthepony.kommons
|
projectGroup=ru.dbotthepony.kommons
|
||||||
projectVersion=3.2.0
|
projectVersion=3.2.1
|
||||||
|
|
||||||
guavaDepVersion=33.0.0
|
guavaDepVersion=33.0.0
|
||||||
gsonDepVersion=2.8.9
|
gsonDepVersion=2.8.9
|
||||||
|
@ -8,14 +8,14 @@ import java.util.random.RandomGenerator
|
|||||||
* Internal state is presented as 64-bit integer, and high-order bits of internal state are
|
* Internal state is presented as 64-bit integer, and high-order bits of internal state are
|
||||||
* used to generate numbers.
|
* used to generate numbers.
|
||||||
*/
|
*/
|
||||||
open class LCG64Random(private var seed: Long) : RandomGenerator {
|
open class LCG64Random(protected var seed: Long) : RandomGenerator {
|
||||||
final 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
|
||||||
return a.shl(32) or b
|
return a.shl(32) or b
|
||||||
}
|
}
|
||||||
|
|
||||||
final override fun nextInt(): Int {
|
override fun nextInt(): Int {
|
||||||
this.seed = MULTIPLIER * this.seed + INCREMENT
|
this.seed = MULTIPLIER * this.seed + INCREMENT
|
||||||
return this.seed.ushr(32).toInt()
|
return this.seed.ushr(32).toInt()
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,10 @@ package ru.dbotthepony.kommons.random
|
|||||||
import java.util.random.RandomGenerator
|
import java.util.random.RandomGenerator
|
||||||
|
|
||||||
open class Xoshiro256PlusPlusRandom protected constructor(
|
open class Xoshiro256PlusPlusRandom protected constructor(
|
||||||
private var s0: Long,
|
protected var s0: Long,
|
||||||
private var s1: Long,
|
protected var s1: Long,
|
||||||
private var s2: Long,
|
protected var s2: Long,
|
||||||
private var s3: Long,
|
protected var s3: Long,
|
||||||
mark: Nothing?
|
mark: Nothing?
|
||||||
) : RandomGenerator {
|
) : RandomGenerator {
|
||||||
init {
|
init {
|
||||||
@ -32,7 +32,7 @@ open class Xoshiro256PlusPlusRandom protected constructor(
|
|||||||
s3 = rng.nextLong()
|
s3 = rng.nextLong()
|
||||||
}
|
}
|
||||||
|
|
||||||
final override fun nextLong(): Long {
|
override fun nextLong(): Long {
|
||||||
val result = (s0 + s3).rotateLeft(23) + s1
|
val result = (s0 + s3).rotateLeft(23) + s1
|
||||||
val t = s1.shl(17)
|
val t = s1.shl(17)
|
||||||
s2 = s2.xor(s0)
|
s2 = s2.xor(s0)
|
||||||
|
@ -3,10 +3,10 @@ package ru.dbotthepony.kommons.random
|
|||||||
import java.util.random.RandomGenerator
|
import java.util.random.RandomGenerator
|
||||||
|
|
||||||
open class Xoshiro256StarStarRandom protected constructor(
|
open class Xoshiro256StarStarRandom protected constructor(
|
||||||
private var s0: Long,
|
protected var s0: Long,
|
||||||
private var s1: Long,
|
protected var s1: Long,
|
||||||
private var s2: Long,
|
protected var s2: Long,
|
||||||
private var s3: Long,
|
protected var s3: Long,
|
||||||
mark: Nothing?
|
mark: Nothing?
|
||||||
) : RandomGenerator {
|
) : RandomGenerator {
|
||||||
init {
|
init {
|
||||||
@ -32,7 +32,7 @@ open class Xoshiro256StarStarRandom protected constructor(
|
|||||||
s3 = rng.nextLong()
|
s3 = rng.nextLong()
|
||||||
}
|
}
|
||||||
|
|
||||||
final override fun nextLong(): Long {
|
override fun nextLong(): Long {
|
||||||
val result = (s1 * 5).rotateLeft(7) * 9
|
val result = (s1 * 5).rotateLeft(7) * 9
|
||||||
val t = s1.shl(17)
|
val t = s1.shl(17)
|
||||||
s2 = s2.xor(s0)
|
s2 = s2.xor(s0)
|
||||||
|
Loading…
Reference in New Issue
Block a user