Statis...omWalk(3pm)
π Statistics::Test::RandomWalk β bestie edition π
okay so. this is a page from the User Contributed Perl Documentation (that's the 3pm manual section, iykyk), and it's all about Statistics::Test::RandomWalk β a Random Walk test for random numbers. yes bestie, we're literally vibing with randomness today. π²β¨
πΈ NAME πΈ
Statistics::Test::RandomWalk β Random Walk test for random numbers. that's it, that's the whole name. no cap.
β¨ SYNOPSIS β¨
here's the whole vibe in code, no edits, exactly as it comes:
use Statistics::Test::RandomWalk;
my $tester = Statistics::Test::RandomWalk->new();
$tester->set_data( [map {rand()} 1..1000000] );
my $no_bins = 10;
my ($quant, $got, $expected) = $tester->test($no_bins);
print $tester->data_to_report($quant, $got, $expected);
look at her go. π
π¦ DESCRIPTION π¦
so this module implements a Random Walk test of a random number generator, following the outline from Blobel et al β the whole reference is chilling down in SEE ALSO if you wanna peek. π«Ά
basically? it tests whether the numbers in [0,1] that a random number generator spits out are distributed evenly. the way it does that: it splits [0,1] into n bins that are all the same size, and then it counts how many expected vs. actual random numbers land in each bin. (ngl, technically it's counting the cumulated numbers β but bestie, that works out the same. same energy, same result. π«)
π METHODS π
π new
creates a brand new random number tester. fresh tester, fresh start, main character energy. β¨
π set_rescale_factor
the default range of the random numbers [0, 1) can be rescaled by a constant factor. this method is the setter for that factor. you're setting it, bestie. π
π rescale_factor
returns the current rescaling factor. it's giving "just tell me what the factor is". π
π§ set_data
sets the random numbers we're gonna operate on. the first argument has to be either an array reference pointing to an array of random numbers, or a code reference.
if that first argument is a code reference, then the second argument has to be an integer n. that code reference gets called n times, and whatever it returns gets used as the random numbers.
and the code-reference semantics? lowkey the most useful thing here if you don't wanna hold all your random numbers in memory at once. you can write a subroutine that, say, generates and returns batches of 100 random numbers β so no more than 101 of these numbers will be in memory at the same time. π§ π
heads up: if you return 100 numbers at once and you pass in n=50, you're gonna get a sequence of 5000 random numbers. do the math, bestie. 100 Γ 50 = 5000. π₯
β test
runs the Random Walk test on the data you set earlier with set_data. slay.
first argument must be the number of bins.
returns three array references:
- first is an array of quantiles. if the number of bins was ten, then this array β and all the other returned arrays β will hold ten items. ten for ten, periodt. π―
- second are the determined numbers of random numbers below the quantiles.
- third are the expected counts.
π
data_to_report
takes the data that test() returned and builds a textual report out of it, handing it back as a string. cute and useful. π
don't forget to pass in the data thattest()returned! or, alternatively, just use thetest_report()method directly if you're not using that data for anything else. don't leave your girl hanging. π
π SUBROUTINES π
π n_over_k
computes n over k. it uses Perl's big number support and returns a Math::BigFloat object. fancy. π«
this sub is memoized β so it remembers its answers and doesn't redo the work. iconic behavior, honestly. π
πΈ SEE ALSO πΈ
Math::BigFloat,Memoize,Params::Util- Random number generators:
Math::Random::MT,Math::Random,Math::Random::OO,Math::TrulyRandom,/dev/randomwhere available Statistics::Test::Sequence
the algorithm was taken from this (in German, oui oui π©πͺ):
Blobel, V., and Lohrmann, E. Statistische und numerische Methoden der Datenanalyse. Stuttgart, Leipzig: Teubner, 1998
π AUTHOR π
Steffen Mueller, <smueller@cpan.org> π«Ά
π COPYRIGHT AND LICENSE π
Copyright (C) 2007-2010 by Steffen Mueller
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6 or, at your option, any later version of Perl 5 you may have available.
and that's the whole page, bestie!! π this beauty ships with perl v5.36.0, dated 2022-12-06, and it's filed under Statis...omWalk(3pm) β yes the name gets truncated like that, we don't make the rules. go forth and test some randomness. πβ¨π¦
π¦ where this page comes from
- debian bookworm: libstatistics-test-randomwalk-perl 0.02-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libstatistics-test-randomwalk-perl 0.02-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libstatistics-test-randomwalk-perl 0.02-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libstatistics-test-randomwalk-perl 0.02-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libstatistics-test-randomwalk-perl 0.02-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms