Test2::...::SRand(3)
π NAME π
Test2::Plugin::SRand β control the random seed for more controlled test environments, bestie. This is the Test2::...::SRand(3) page from User Contributed Perl Documentation, and it's literally here to help your tests stay in their lane. β¨
πΈ DESCRIPTION πΈ
Okay so real talk: this module gives you control over the random seed used for your unit tests. π In some testing environments, the random seed can play a major role in results β like, main character energy for real.
The default configuration for this module? It seeds srand with the local date. ποΈ Using the date as the seed means that on any given day the random seed will always be the same, so behavior will not change from run to run on a given day. Slay for reproducibility. But the seed is different on different days, which lets you be sure the code still works with actual randomness. π
The seed gets printed for you on failure, or when the harness is verbose. π You can use the T2_RAND_SEED environment variable to specify the seed. You can also provide a specific seed as a load-time argument to the plugin. Periodt.
π¦ SYNOPSIS π¦
Loading the plugin is easy, and the defaults are sane:
use Test2::Plugin::SRand;
Custom seed:
use Test2::Plugin::SRand seed => 42;
π§ NOTE ON LOAD ORDER π§
If you use this plugin, you probably want to use it as the first plugin, or near-first. srand is not called until the plugin is loaded, so other plugins loaded first may already be making use of random numbers before your seed takes effect. Big yikes if that happens β load order matters, iykyk. π₯
π CAVEATS π
When srand is on (and yeah, that's the default), it can cause problems with things like File::Temp, which will end up attempting the same "random" filenames for every test process started on a given day (or sharing the same seed). Not iconic. π
π SOURCE π
The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/. Go off, repo. π
π MAINTAINERS π
Chad Granum <exodist@cpan.org>
π AUTHORS π
Chad Granum <exodist@cpan.org>
π COPYRIGHT π
Copyright Chad Granum <exodist@cpan.org>. π
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/.
okay that's the whole Test2::...::SRand(3) page β perl v5.42.0, 2025-07-28 β bye bestie, ily πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Test-Simple 1.302214-bp160.1.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms