17 lines
350 B
Kotlin
17 lines
350 B
Kotlin
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)
|
|
}
|
|
}
|