implement optimizations
This commit is contained in:
16
src/commonMain/kotlin/com/infendro/random/PRNG.kt
Normal file
16
src/commonMain/kotlin/com/infendro/random/PRNG.kt
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.infendro.random
|
||||
|
||||
import kotlin.random.Random
|
||||
|
||||
abstract class PRNG : Random() {
|
||||
abstract fun seed(seed: ByteArray)
|
||||
|
||||
protected abstract fun generate(): Int
|
||||
|
||||
override fun nextBits(bitCount: Int): Int {
|
||||
require(bitCount in 0..32)
|
||||
|
||||
if (bitCount == 0) return 0
|
||||
return generate() ushr (32 - bitCount)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user