NAME

Langertha::Holmgang::Random - The seeded private random source for case generators

VERSION

version 0.001

SYNOPSIS

use Langertha::Holmgang::Random;

my $rng = Langertha::Holmgang::Random->new( seed => 4711 );

my $n    = $rng->int( 10, 99 );            # 10 .. 99, both included
my $f    = $rng->float;                    # 0 <= $f < 1
my $host = $rng->pick(qw( web1 web2 db1 ));
my @deck = $rng->shuffle( 1 .. 10 );

DESCRIPTION

The random source a generator of the case DSL gets ("generate" in Langertha::Holmgang, ADR 0007): a seeded object of its own, so the same seed gives the same numbers on every perl and platform, and no other module's use of rand or srand can move it.

The algorithm is fixed: xoshiro128** (Blackman and Vigna) over four 32-bit words, seeded by splitmix32 from the seed. Changing it changes every generated suite, so it never changes without a version raised in every suite that generates. Pure Perl; it needs a perl with 64-bit integers, as Langertha::Holmgang::Haystack does.

Never srand/rand in a generator: the global generator is shared with every other module, so the cases would depend on what ran before.

seed

Required. An integer from 0 to 4294967295 (2**32 - 1).

next_u32

The next raw value, an integer from 0 to 4294967295. The other methods draw from it.

int

my $n = $rng->int( 1, 6 );

An integer from $lo to $hi, both included, every value equally likely.

float

A number from 0 (included) to 1 (excluded), in steps of 2**-32.

pick

my $host = $rng->pick( @hosts );

One element of the list.

shuffle

my @order = $rng->shuffle( @items );

The list in a random order (Fisher–Yates).

SUPPORT

Issues

Please report bugs and feature requests at https://github.com/Getty/langertha-holmgang/issues.

IRC

Join #langertha on irc.perl.org or message Getty directly.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <torsten@raudssus.de>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.