implement xoshiro256++ and xoshiro256**
All checks were successful
/ test (pull_request) Successful in 38s

This commit is contained in:
2026-01-30 15:16:48 +01:00
parent 2c6fe0a7d9
commit 2ae6fda70e
2 changed files with 56 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
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 Xoshiro256pp : 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[0] + s[3]).rotateLeft(23) + s[0]
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()
}
}

View File

@@ -0,0 +1,28 @@
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()
}
}