Files
prng.kt/README.md

50 lines
1.1 KiB
Markdown

# prng-kt
`prng-kt` is a Kotlin Multiplatform library that provides common [Pseudorandom Number Generators](https://en.wikipedia.org/wiki/Pseudorandom_number_generator).
Supported [PRNG](https://en.wikipedia.org/wiki/Pseudorandom_number_generator) algorithms:
- LCG
- xoshiro256++
- xoshiro256**
Supported [CSPRNG](https://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator) algorithms:
- HMAC-DRBG
## Installation
Add the following to your `build.gradle.kts`.
```kotlin
repositories {
maven("https://git.infendro.com/api/packages/Infendro/maven")
}
dependencies {
implementation("com.infendro:prng:1.3.0")
}
```
## Usage
```kotlin
fun main() {
// create PRNG instance
val rng = CSPRNG.HMAC(`SHA-256`)
// seed PRNG to receive deterministic numbers
rng.seed(/* seed */)
val a = rng.nextInt()
val b = rng.nextInt()
val c = rng.nextInt()
// reseed PRNG to add additional entropy
rng.reseed(/* entropy */)
val d = rng.nextInt()
val e = rng.nextInt()
val f = rng.nextInt()
// a, b, and c will be deterministic
// d, e, and f will be random (assuming entropy is random)
}
```