Files
prng.kt/README.md
Infendro 517b58a3df update README
small rewording, link wikipedia article
2025-12-14 14:41:30 +01:00

61 lines
1.5 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
Supported [CSPRNG](https://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator) algorithms:
- HMAC DRBG
## Targets
| Target | Status |
|------------------|---------------|
| JVM | Supported |
| JavaScript | Supported |
| Native (Linux) | Supported |
| Native (Windows) | Not Supported |
## 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.2.0")
}
```
## Usage
```kotlin
import com.infendro.hash.sha2.`SHA-256`
import com.infendro.random.csprng.CSPRNG
fun main() {
// create a PRNG instance
val rng = CSPRNG.HMAC(`SHA-256`)
// seed the PRNG to receive predictable results
rng.seed(/* some seed */)
val a = rng.nextInt()
val b = rng.nextInt()
val c = rng.nextInt()
// reseed the PRNG to add entropy to the following results
rng.reseed(/* some random entropy */)
val d = rng.nextInt()
val e = rng.nextInt()
val f = rng.nextInt()
// each run:
// a, b, and c will be predictable
// d, e, and f will be random (assuming the entropy is also random)
}
```