Statis...omWalk(3pm)

πŸ“¦
version 0.02 Β· 2 versions
  • 0.02 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.02 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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:

  1. 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. 🎯
  2. second are the determined numbers of random numbers below the quantiles.
  3. 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 that test() returned! or, alternatively, just use the test_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/random where 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 (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