Files
prng.kt/README.md
Infendro 2aed836e67
All checks were successful
/ test (pull_request) Successful in 32s
Upgrade dependencies
2026-02-19 12:46:41 +01:00

1.1 KiB

prng-kt

prng-kt is a Kotlin Multiplatform library that provides common Pseudorandom Number Generators.

Supported PRNG algorithms:

  • LCG
  • Xoshiro256++
  • Xoshiro256**

Supported CSPRNG algorithms:

  • HMAC-DRBG

Installation

Add the following to your build.gradle.kts.

repositories {
    maven("https://git.infendro.com/api/packages/Infendro/maven")
}

dependencies {
    implementation("com.infendro:prng:1.3.0")
}

Usage

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)
}