secureRandom

actual fun secureRandom(): Random(source)

Returns a cryptographically secure random number generator for the current platform.

Each platform uses its native secure random source: java.security.SecureRandom on JVM and Android, SecRandomCopyBytes on Apple platforms, /dev/urandom on Linux, BCryptGenRandom on Windows, and crypto.getRandomValues on JS and Wasm.

The returned Random instance is suitable for generating random samples in distribution sample() methods. It should not be used for high-throughput scenarios where performance is critical — use kotlin.random.Random instead in those cases.

Example:

val rng = secureRandom()
rng.nextDouble() // cryptographically random value in [0, 1)

Return

a platform-specific Random backed by a cryptographic random source.

actual fun secureRandom(): Random(source)

Returns a cryptographically secure random number generator for the current platform.

Each platform uses its native secure random source: java.security.SecureRandom on JVM and Android, SecRandomCopyBytes on Apple platforms, /dev/urandom on Linux, BCryptGenRandom on Windows, and crypto.getRandomValues on JS and Wasm.

The returned Random instance is suitable for generating random samples in distribution sample() methods. It should not be used for high-throughput scenarios where performance is critical — use kotlin.random.Random instead in those cases.

Example:

val rng = secureRandom()
rng.nextDouble() // cryptographically random value in [0, 1)

Return

a platform-specific Random backed by a cryptographic random source.

actual fun secureRandom(): Random(source)

Returns a cryptographically secure random number generator for the current platform.

Each platform uses its native secure random source: java.security.SecureRandom on JVM and Android, SecRandomCopyBytes on Apple platforms, /dev/urandom on Linux, BCryptGenRandom on Windows, and crypto.getRandomValues on JS and Wasm.

The returned Random instance is suitable for generating random samples in distribution sample() methods. It should not be used for high-throughput scenarios where performance is critical — use kotlin.random.Random instead in those cases.

Example:

val rng = secureRandom()
rng.nextDouble() // cryptographically random value in [0, 1)

Return

a platform-specific Random backed by a cryptographic random source.

expect fun secureRandom(): Random(source)

Returns a cryptographically secure random number generator for the current platform.

Each platform uses its native secure random source: java.security.SecureRandom on JVM and Android, SecRandomCopyBytes on Apple platforms, /dev/urandom on Linux, BCryptGenRandom on Windows, and crypto.getRandomValues on JS and Wasm.

The returned Random instance is suitable for generating random samples in distribution sample() methods. It should not be used for high-throughput scenarios where performance is critical — use kotlin.random.Random instead in those cases.

Example:

val rng = secureRandom()
rng.nextDouble() // cryptographically random value in [0, 1)

Return

a platform-specific Random backed by a cryptographic random source.

actual fun secureRandom(): Random(source)

Returns a cryptographically secure random number generator backed by the Web Crypto API.

Uses crypto.getRandomValues to fill an internal buffer of 64 integers, refilling when exhausted. This avoids calling into the native crypto API on every random number request.

Return

a Random instance backed by crypto.getRandomValues.

actual fun secureRandom(): Random(source)

Returns a cryptographically secure random number generator for the current platform.

Each platform uses its native secure random source: java.security.SecureRandom on JVM and Android, SecRandomCopyBytes on Apple platforms, /dev/urandom on Linux, BCryptGenRandom on Windows, and crypto.getRandomValues on JS and Wasm.

The returned Random instance is suitable for generating random samples in distribution sample() methods. It should not be used for high-throughput scenarios where performance is critical — use kotlin.random.Random instead in those cases.

Example:

val rng = secureRandom()
rng.nextDouble() // cryptographically random value in [0, 1)

Return

a platform-specific Random backed by a cryptographic random source.

actual fun secureRandom(): Random(source)

Returns a cryptographically secure random number generator for the current platform.

Each platform uses its native secure random source: java.security.SecureRandom on JVM and Android, SecRandomCopyBytes on Apple platforms, /dev/urandom on Linux, BCryptGenRandom on Windows, and crypto.getRandomValues on JS and Wasm.

The returned Random instance is suitable for generating random samples in distribution sample() methods. It should not be used for high-throughput scenarios where performance is critical — use kotlin.random.Random instead in those cases.

Example:

val rng = secureRandom()
rng.nextDouble() // cryptographically random value in [0, 1)

Return

a platform-specific Random backed by a cryptographic random source.

actual fun secureRandom(): Random(source)

Returns a cryptographically secure random number generator for the current platform.

Each platform uses its native secure random source: java.security.SecureRandom on JVM and Android, SecRandomCopyBytes on Apple platforms, /dev/urandom on Linux, BCryptGenRandom on Windows, and crypto.getRandomValues on JS and Wasm.

The returned Random instance is suitable for generating random samples in distribution sample() methods. It should not be used for high-throughput scenarios where performance is critical — use kotlin.random.Random instead in those cases.

Example:

val rng = secureRandom()
rng.nextDouble() // cryptographically random value in [0, 1)

Return

a platform-specific Random backed by a cryptographic random source.

actual fun secureRandom(): Random(source)

Returns a cryptographically secure random number generator for the current platform.

Each platform uses its native secure random source: java.security.SecureRandom on JVM and Android, SecRandomCopyBytes on Apple platforms, /dev/urandom on Linux, BCryptGenRandom on Windows, and crypto.getRandomValues on JS and Wasm.

The returned Random instance is suitable for generating random samples in distribution sample() methods. It should not be used for high-throughput scenarios where performance is critical — use kotlin.random.Random instead in those cases.

Example:

val rng = secureRandom()
rng.nextDouble() // cryptographically random value in [0, 1)

Return

a platform-specific Random backed by a cryptographic random source.

actual fun secureRandom(): Random(source)

Returns a cryptographically secure random number generator for the current platform.

Each platform uses its native secure random source: java.security.SecureRandom on JVM and Android, SecRandomCopyBytes on Apple platforms, /dev/urandom on Linux, BCryptGenRandom on Windows, and crypto.getRandomValues on JS and Wasm.

The returned Random instance is suitable for generating random samples in distribution sample() methods. It should not be used for high-throughput scenarios where performance is critical — use kotlin.random.Random instead in those cases.

Example:

val rng = secureRandom()
rng.nextDouble() // cryptographically random value in [0, 1)

Return

a platform-specific Random backed by a cryptographic random source.