W3cubDocs

/Crystal

module Random::Secure

Overview

Random::Secure generates random numbers from a secure source provided by the system.

It uses a cryptographically secure pseudorandom number generator (CSPRNG) for cryptography and secure usages such as generating secret keys, or to seed another pseudorandom number generator (PRNG).

Random::Secure.rand(6)            # => 4
[1, 5, 6].shuffle(Random::Secure) # => [6, 1, 5]

On OpenBSD, it uses arc4random, on Linux getrandom (if the kernel supports it), on Windows RtlGenRandom, and falls back to reading from /dev/urandom on UNIX systems.

Extended Modules

Defined in:

random/secure.cr

Instance Method Summary

Instance Method Detail

def next_uSource

def random_bytes(buf : Bytes)Source

© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/Random/Secure.html