Test2::...::SRand(3pm)
okay bestie, welcome to the manual page for Test2::...::SRand(3pm) from the Perl Programmers Reference Guide β yes, the manual name is folded in right here, and this one is all about making your test randomness behave. π
πΈ NAME πΈ
Test2::Plugin::SRand β Control the random seed for more controlled test environments.
β¨ DESCRIPTION β¨
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.
The default configuration for this module will seed 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. However, the seed is different on different days, allowing you to be sure the code still works with actual randomness. π²
The seed is 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.
π 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, or near-first, plugin. 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.
π CAVEATS π
Whensrandis on (default) it can cause problems with things likeFile::Temp, which will end up attempting the same "random" filenames for every test process started on a given day (or sharing the same seed).
π₯ SOURCE π₯
The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/.
π 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/
This lil manpage sign-off is brought to you by perl v5.42.3, dated 2026-11-03, and it's the Test2::...::SRand(3pm) page β slay, go forth, and seed responsibly π
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl 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