Infendro feecfa49b9 refactor, implement LCG
LCG ... Linear Congruential Generator
2025-11-10 18:52:19 +01:00
2025-07-24 20:49:21 +02:00
2025-11-10 18:52:19 +01:00
2025-07-24 20:49:21 +02:00
2025-11-10 18:52:19 +01:00
2025-08-16 21:27:07 +02:00
2025-08-16 21:27:07 +02:00
2025-07-24 20:49:21 +02:00
2025-10-04 12:41:52 +02:00
2025-07-24 20:49:21 +02:00

Kotlin OTP

This library provides various Pseudorandom Number Generator implementations in Kotlin Multiplatform.

Features

  • Generate random numbers using Kotlin's Random interface.
  • Seed the PRNGs to receive predictable results.
  • Reseed the PRNGs to add entropy to the following results.
  • HMAC DRBG
  • Multiplatform support
    • JVM
    • JavaScript
    • Native (Linux)

Installation

Add the following to your build.gradle.kts.

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

dependencies {
    implementation("com.infendro:random:1.1.0")
}

Usage

import com.infendro.hash.SHA256
import com.infendro.random.PRNG

fun main() {
    // create a PRNG instance
    val rng = PRNG.HMAC(SHA256)

    // 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)
}
Description
No description provided
Readme 170 KiB
Languages
Kotlin 100%