Math::...Uniform(3pm)

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

πŸ’– Math::Random::OO::Uniform β€” the manual, but make it cute πŸ’–

okay so bestie, you're reading a User Contributed Perl Documentation page, and the module in question is Math::Random::OO::Uniform. It lives in the Math::Random::OO family and it does exactly one thing and it does it flawlessly: it hands you random reals from the uniform probability distribution. That's it. That's the girl. πŸ‘‘


✨ VERSION ✨

version 0.22 β€” the era we're living in, no cap.


🌸 SYNOPSIS 🌸

Here's the whole vibe in one code block, mwah:

  use Math::Random::OO::Uniform;
  push @prngs,
      Math::Random::OO::Uniform->new(),     # range [0,1)
      Math::Random::OO::Uniform->new(5),    # range [0,5)
      Math::Random::OO::Uniform->new(-1,1); # range [-1,1)
  $_->seed(42) for @prngs;
  print( $_->next() . "\n" ) for @prngs;

Look at her. Three generators, three different ranges, all seeded with 42, all printing their little numbers. iconic behaviour honestly. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So this is a subclass of Math::Random::OO, and it generates random reals from a uniform probability distribution. That means every number in the range has the same chance as every other number. Fair. Balanced. Demure, even. 🧚


πŸŽ€ METHODS πŸŽ€

πŸ’œ new

  $prng1 = Math::Random::OO::Uniform->new();
  $prng2 = Math::Random::OO::Uniform->new($high);
  $prng3 = Math::Random::OO::Uniform->new($low,$high);

new takes up to two optional parameters and returns a brand new Math::Random::OO::Uniform object. Let's break it down because the three moods are all different:

  • No parameters β€” the object generates random numbers in the range of zero (inclusive) to one (exclusive). So [0,1), basically.
  • One parameter β€” the object generates random numbers from zero (inclusive) to the value of the parameter (exclusive).
⚠️ Important lore: the object does this with multiplication, so if the parameter is negative, the function will return negative numbers. The original docs say this is a feature or bug, depending on your point of view β€” and honestly? That's the most real thing in this whole manpage. πŸ’€
  • Two parameters β€” the object generates random numbers from the first parameter (inclusive) to the second parameter (exclusive). And a little secret: as long as you have two parameters, new will put them in the right order. So she's got your back. 🫢

πŸ“ seed

  $rv = $prng->seed( @seeds );

This method seeds the random number generator. Currently, only the first seed value matters β€” the rest are just there, chilling. It should be a positive integer. ✨

🌈 next

  $rnd = $prng->next();

This method returns the next random number from the random number generator. It does not take any parameters. No arguments, no drama, just vibes and numbers. πŸ’–


πŸ‘‘ AUTHOR πŸ‘‘

David Golden <dagolden@cpan.org> β€” the mastermind, the moment, the main character. 🌟


This software is Copyright (c) 2013 by David Golden.

This is free software, licensed under:

  The Apache License, Version 2.0, January 2004

Slay, legally speaking. βš–οΈβœ¨


okay bestie that's the whole page, you ate it, go generate some uniform random numbers and be free πŸ¦‹πŸ’–

this was perl v5.36.0, dated 2022-12-12, from Math::...Uniform(3pm) β€” bye babes, ily, use protection (seed your PRNG) πŸ’…πŸŽ€