29 lines
706 B
Kotlin
29 lines
706 B
Kotlin
package com.infendro.random.prng
|
|
|
|
import com.infendro.bytes.bytearray.toLongArray
|
|
import com.infendro.hash.sha2.`SHA-256`
|
|
import com.infendro.random.PRNG
|
|
import kotlin.properties.Delegates.notNull
|
|
|
|
class Xoshiro256ss : PRNG() {
|
|
private var s: LongArray by notNull()
|
|
|
|
override fun seed(seed: ByteArray) {
|
|
s = `SHA-256`.hash(seed).toLongArray()
|
|
}
|
|
|
|
override fun generate(): Int {
|
|
val result = (s[1] * 5).rotateLeft(7) * 9
|
|
|
|
val t = s[1] shl 17
|
|
s[2] = s[2] xor s[0]
|
|
s[3] = s[3] xor s[1]
|
|
s[1] = s[1] xor s[2]
|
|
s[0] = s[0] xor s[3]
|
|
s[2] = s[2] xor t
|
|
s[3] = s[3].rotateLeft(45)
|
|
|
|
return (result ushr 32).toInt()
|
|
}
|
|
}
|