
Retrieves cryptographically-secure random bytes from the OS RNG via a single getrandom(dest: ByteArray) call, delegating to native entropy sources for a minimal API and small footprint.
Kotlin Multiplatform port of the
getrandom Rust crate (version
0.2.15) — a small cross-platform library for retrieving
cryptographically-secure random bytes from the OS-provided RNG.
getrandom mirrors the upstream Rust crate's single public function:
pub fn getrandom(dest: &mut [u8]) -> Result<(), Error>becomes Kotlin:
public fun getrandom(dest: ByteArray): Result<Unit>Each platform's actual delegates to the most appropriate OS-provided
entropy source:
| Source set | Backend |
|---|---|
linuxMain |
getrandom(2) syscall via platform.posix.getrandom
|
mingwMain |
BCryptGenRandom via Windows CNG |
appleMain |
CCRandomGenerateBytes from CommonCrypto |
androidNativeMain |
Bionic getrandom(2) syscall |
androidMain |
java.security.SecureRandom |
jvmMain |
java.security.SecureRandom |
wasmWasiMain |
random_get from WASI preview1 |
jsMain |
crypto.getRandomValues (browser) / crypto.randomFillSync (node) |
wasmJsMain |
same as jsMain via js(...)
|
commonMain.dependencies {
implementation("io.github.kotlinmania:getrandom-kotlin:0.1.0")
}getrandom 0.2.15
rust-random/getrandom
Dual-licensed under the MIT license and the Apache License, Version 2.0, matching the upstream crate.
Kotlin Multiplatform port of the
getrandom Rust crate (version
0.2.15) — a small cross-platform library for retrieving
cryptographically-secure random bytes from the OS-provided RNG.
getrandom mirrors the upstream Rust crate's single public function:
pub fn getrandom(dest: &mut [u8]) -> Result<(), Error>becomes Kotlin:
public fun getrandom(dest: ByteArray): Result<Unit>Each platform's actual delegates to the most appropriate OS-provided
entropy source:
| Source set | Backend |
|---|---|
linuxMain |
getrandom(2) syscall via platform.posix.getrandom
|
mingwMain |
BCryptGenRandom via Windows CNG |
appleMain |
CCRandomGenerateBytes from CommonCrypto |
androidNativeMain |
Bionic getrandom(2) syscall |
androidMain |
java.security.SecureRandom |
jvmMain |
java.security.SecureRandom |
wasmWasiMain |
random_get from WASI preview1 |
jsMain |
crypto.getRandomValues (browser) / crypto.randomFillSync (node) |
wasmJsMain |
same as jsMain via js(...)
|
commonMain.dependencies {
implementation("io.github.kotlinmania:getrandom-kotlin:0.1.0")
}getrandom 0.2.15
rust-random/getrandom
Dual-licensed under the MIT license and the Apache License, Version 2.0, matching the upstream crate.