refactor, implement LCG

LCG ... Linear Congruential Generator
This commit is contained in:
2025-11-10 18:52:19 +01:00
parent 7db8972e27
commit feecfa49b9
7 changed files with 109 additions and 69 deletions

View File

@@ -1,36 +0,0 @@
package com.infendro.random
import com.infendro.bytearray.toInt
import com.infendro.hash.HashFunction
import kotlin.random.Random
abstract class PRNG : Random() {
abstract fun seed(
seed: ByteArray,
)
abstract fun reseed(
entropy: ByteArray,
)
abstract fun generate(
count: Int,
): ByteArray
override fun nextBits(
bitCount: Int,
): Int {
if (bitCount !in 0..32) throw Exception()
if (bitCount == 0) return 0
return generate(4).toInt() ushr (32 - bitCount)
}
companion object {
fun HMAC(
function: HashFunction,
): HMAC {
return com.infendro.random.HMAC(function)
}
}
}