https://stockholm.ninkilim.com/random
Home | Articles | Postings | Weather | Top | Trending | Status
Login
NAME
    Farid::Model::Random provides a simple frontend to /dev/random

    Webpage: <https://farid.ps/random>

SYNOPSIS
     perl Random.pm [length]

     use Farid::Model::Random;
     print Farid::Model::Random->string([length], [charset]);
     print Farid::Model::Random->alnum([length]);
     print Farid::Model::Random->hex([length]);
     print Farid::Model::Random->num([length]);

RATIONALE
    Generating random tokens (e.g. passwords) is a common task but
    implementations often get it wrong.

    Common mistakes include using "rand" in perlfunc or String::Random which
    returns pseudo-random data based on a seed value or modulo arithmetic
    like "$byte % $n" and scaling methods like "int($byte / 255 * $n)" which
    introduce bias unless 256 is a multiple of $n

    Other implementations like Bytes::Random::Secure come with their own
    implementation of a Pseudo-Random Number Generator which makes them
    rather large and difficult to audit.

IMPLEMENTATION
    This implementation is intentionally small (less than 100 lines of code)
    to make auditing straightforward.

    The module also exposes its own POD and source code at runtime, thereby
    serving as library, CLI tool, documentation, and source distribution.

    It relies on the Linux kernel's implementation of a CSPRNG, which - as
    of Linux 5.6 - uses the ChaCha20 algorithm to implement a DRBG. Once the
    initial entropy pool has been seeded, both /dev/random and /dev/urandom
    draw from the same DRBG and no longer block.

    It intentionally reads only 32 bytes at a time to allow the kernel to
    replenish entropy between reads, reducing exposure if the DRBG's
    internal state were ever leaked.

LICENSE
    Provided as-is under GPLv3. No warranties. Use at your own risk.

alnum: ylIsQ57E
hex: f036883a
num: 04113548