Venus::Random
Random Class
Random Class for Perl 5
method: alphanumeric method: alphanumerics method: base64 method: bit method: bits method: boolean method: byte method: bytes method: character method: characters method: collect method: digest method: digit method: digits method: float method: hexdecimal method: hexdecimals method: id method: letter method: letters method: lowercased method: new method: nonce method: nonzero method: number method: numbers method: password method: pick method: range method: repeat method: reseed method: reset method: restore method: select method: shuffle method: symbol method: symbols method: token method: uppercased method: urlsafe method: uuid
package main;
use Venus::Random;
my $random = Venus::Random->new(42);
# my $bit = $random->bit;
# 1
This package provides an object-oriented interface for Perl's pseudo-random number generator (or PRNG) which produces a deterministic sequence of bits which approximate true randomness.
Venus::Kind::Utility
Venus::Role::Accessible Venus::Role::Buildable Venus::Role::Valuable
The alphanumeric method returns a random alphanumeric character, which is either a "digit", or "letter" value.
alphanumeric() (string)
{ since => '4.15', }
=example-1 alphanumeric
# given: synopsis
package main;
my $alphanumeric = $random->alphanumeric;
# "C"
# $alphanumeric = $random->alphanumeric;
# 0
The alphanumerics method returns n "alphanumeric" characters based on the number (i.e. count) provided.
alphanumerics(number $count) (string)
{ since => '4.15', }
=example-1 alphanumerics
# given: synopsis
package main;
my $alphanumerics = $random->alphanumerics(5);
# "C0Mma"
# $alphanumerics = $random->alphanumerics(5);
# "x5498"
The base64 method returns a unique randomly generated base64 encoded string.
base64() (string)
{ since => '4.15', }
The bits method returns n "bit" characters based on the number (i.e. count) provided.
bits(number $count) (string)
{ since => '4.15', }
=example-1 bits
# given: synopsis
package main;
my $bits = $random->bits(5);
# "01111"
# $bits = $random->bits(5);
# "01100"
The bit method returns a 1 or 0 value, randomly.
bit() (number)
{ since => '1.11', }
=example-1 bit
# given: synopsis
package main;
my $bit = $random->bit;
# 0
# $bit = $random->bit;
# 1
The boolean method returns a true or false value, randomly.
boolean() (boolean)
{ since => '1.11', }
=example-1 boolean
# given: synopsis
package main;
my $boolean = $random->boolean;
# 0
# $boolean = $random->boolean;
# 1
The byte method returns random byte characters, randomly.
byte() (string)
{ since => '1.11', }
=example-1 byte
# given: synopsis
package main;
my $byte = $random->byte;
# "\xBE"
# $byte = $random->byte;
# "W"
The bytes method returns n "byte" characters based on the number (i.e. count) provided.
bytes(number $count) (string)
{ since => '4.15', }
=example-1 bytes
# given: synopsis
package main;
my $bytes = $random->bytes(5);
# "\xBE\x57\x1C\x6C\x14"
# $bytes = $random->bytes(5);
# "\xDB\x7F\x7A\xB0\xD5"
The character method returns a random character, which is either a "digit", "letter", or "symbol" value.
character() (string)
{ since => '1.11', }
=example-1 character
# given: synopsis
package main;
my $character = $random->character;
# ")"
# $character = $random->character;
# 4
The characters method returns n "character" characters based on the number (i.e. count) provided.
characters(number $count) (string)
{ since => '4.15', }
=example-1 characters
# given: synopsis
package main;
my $characters = $random->characters(5);
# ")48R+"
# $characters = $random->characters(5);
# "a}[Lb"
The collect method dispatches to the specified method or coderef, repeatedly based on the number of $times specified, and returns the random concatenated results from each dispatched call. By default, if no arguments are provided, this method dispatches to "digit".
collect(number $times, string | coderef $code, any @args) (number | string)
{ since => '1.11', }
=example-1 collect
# given: synopsis
package main;
my $collect = $random->collect;
# 7
# $collect = $random->collect;
# 3
The digest method returns a unique randomly generated "md5" digest.
digest() (string)
{ since => '4.15', }
The digit method returns a random digit between 0 and 9.
digit() (number)
{ since => '1.11', }
=example-1 digit
# given: synopsis
package main;
my $digit = $random->digit;
# 7
# $digit = $random->digit;
# 3
The digits method returns n "digit" characters based on the number (i.e. count) provided.
digits(number $count) (string)
{ since => '4.15', }
=example-1 digits
# given: synopsis
package main;
my $digits = $random->digits(5);
# 73140
# $digits = $random->digits(5);
# 84468
The float method returns a random float.
float(number $place, number $from, number $upto) (number)
{ since => '1.11', }
=example-1 float
# given: synopsis
package main;
my $float = $random->float;
# 1447361.5
# $float = $random->float;
# "0.0000"
The hexdecimal method returns a hexdecimal character.
hexdecimal() (string)
{ since => '4.15', }
The hexdecimals method returns n "hexdecimal" characters based on the number (i.e. count) provided.
hexdecimals(number $count) (string)
{ since => '4.15', }
=example-1 hexdecimals
# given: synopsis
package main;
my $hexdecimals = $random->hexdecimals(5);
# "b5161"
# $hexdecimals = $random->hexdecimals(5);
# "d77bd"
The id method returns a machine unique thread-safe random numerical identifier.
id() (number)
{ since => '4.15', }
The letter method returns a random letter, which is either an "uppercased" or "lowercased" value.
letter() (string)
{ since => '1.11', }
=example-1 letter
# given: synopsis
package main;
my $letter = $random->letter;
# "i"
# $letter = $random->letter;
# "K"
The letters method returns n "letter" characters based on the number (i.e. count) provided.
letters(number $count) (string)
{ since => '4.15', }
=example-1 letters
# given: synopsis
package main;
my $letters = $random->letters(5);
# "iKWMv"
# $letters = $random->letters(5);
# "Papmm"
The lowercased method returns a random lowercased letter.
lowercased() (string)
{ since => '1.11', }
=example-1 lowercased
# given: synopsis
package main;
my $lowercased = $random->lowercased;
# "t"
# $lowercased = $random->lowercased;
# "i"
The new method constructs an instance of the package.
new(any @args) (Venus::Random)
{ since => '4.15', }
The nonce method returns a 10-character "alphanumeric" string.
nonce() (string)
{ since => '4.15', }
The nonzero method dispatches to the specified method or coderef and returns the random value ensuring that it's never zero, not even a percentage of zero. By default, if no arguments are provided, this method dispatches to "digit".
nonzero(string | coderef $code, any @args) (number | string)
{ since => '1.11', }
=example-1 nonzero
# given: synopsis
package main;
my $nonzero = $random->nonzero;
# 7
# $nonzero = $random->nonzero;
# 3
The number method returns a random number within the range provided. If no arguments are provided, the range is from 0 to 2147483647. If only the first argument is provided, it's treated as the desired length of the number.
number(number $from, number $upto) (number)
{ since => '1.11', }
=example-1 number
# given: synopsis
package main;
my $number = $random->number;
# 3427014
# $number = $random->number;
# 3
The numbers method returns n "number" characters (between 1 and 9) based on the number (i.e. count) provided.
numbers(number $count) (string)
{ since => '4.15', }
=example-1 numbers
# given: synopsis
package main;
my $numbers = $random->numbers(5);
# 74141
# $numbers = $random->numbers(5);
# 85578
The password method returns n "characters" based on the number (i.e. count) provided. The default length is 16.
password(number $count) (string)
{ since => '4.15', }
=example-1 password
# given: synopsis
package main;
my $password = $random->password;
# "0*89{745axCMg0m2"
# $password = $random->password;
# "5rV22V24>6Q1v#6N"
The pick method is the random number generator and returns a random number. By default, calling this method is equivalent to call "rand" in perlfunc. This method can be overridden in a subclass to provide a custom generator, e.g. a more cyptographically secure generator.
pick(Num $data) (Num)
{ since => '1.23', }
=example-1 pick
# given: synopsis
package main;
my $pick = $random->pick;
# 0.744525000061007
# $pick = $random->pick;
# 0.342701478718908
The range method returns a random number within the range provided. If no arguments are provided, the range is from 0 to 2147483647.
range(string $from, string $to) (number)
{ since => '1.11', }
=example-1 range
# given: synopsis
package main;
my $range = $random->range(1, 10);
# 8
# $range = $random->range(1, 10);
# 4
The repeat method dispatches to the specified method or coderef, repeatedly based on the number of $times specified, and returns the random results from each dispatched call. In list context, the results from each call is returned as a list, in scalar context the results are concatenated.
repeat(number $times, string | coderef $code, any @args) (number | string)
{ since => '1.11', }
=example-1 repeat
# given: synopsis
package main;
my @repeat = $random->repeat(2);
# (7, 3)
# @repeat = $random->repeat(2);
# (1, 4)
The reseed method sets the "srand" in perlfunc (i.e. the PRNG seed) to the value provided, or the default value used on instanstiation when no seed is passed to the constructor. This method returns the object that invoked it.
reseed(string $seed) (Venus::Random)
{ since => '1.11', }
=example-1 reseed
# given: synopsis
package main;
my $reseed = $random->reseed;
# bless({value => ...}, "Venus::Random")
# my $bit = $random->bit;
# 0
The reset method sets the "srand" in perlfunc (i.e. the PRNG seed) to the default value used on instanstiation when no seed is passed to the constructor. This method returns the object that invoked it.
reset() (Venus::Random)
{ since => '1.11', }
=example-1 reset
# given: synopsis
package main;
my $reset = $random->reset;
# bless({value => ...}, "Venus::Random")
The restore method sets the "srand" in perlfunc (i.e. the PRNG seed) to the original value used by "rand" in perlfunc. This method returns the object that invoked it.
restore() (Venus::Random)
{ since => '1.11', }
=example-1 restore
# given: synopsis
package main;
my $restore = $random->restore;
# bless({value => ...}, "Venus::Random")
The select method returns a random value from the "hashref" or "arrayref" provided.
select(arrayref | hashref $data) (any)
{ since => '1.11', }
=example-1 select
# given: synopsis
package main;
my $select = $random->select(["a".."d"]);
# "c"
# $select = $random->select(["a".."d"]);
# "b"
The shuffle method returns the string provided with its characters randomly rearranged.
shuffle(string $string) (string)
{ since => '4.15', }
The symbol method returns a random symbol.
symbol() (string)
{ since => '1.11', }
=example-1 symbol
# given: synopsis
package main;
my $symbol = $random->symbol;
# "'"
# $symbol = $random->symbol;
# ")"
The symbols method returns n "symbol" characters based on the number (i.e. count) provided.
symbols(number $count) (string)
{ since => '4.15', }
The token method returns a unique randomly generated "md5" digest.
token() (string)
{ since => '4.15', }
The urlsafe method returns a unique randomly generated URL-safe string based on "base64".
urlsafe() (string)
{ since => '4.15', }
The uppercased method returns a random uppercased letter.
uppercased() (string)
{ since => '1.11', }
=example-1 uppercased
# given: synopsis
package main;
my $uppercased = $random->uppercased;
# "T"
# $uppercased = $random->uppercased;
# "I"
The uuid method returns a machine-unique randomly generated psuedo UUID string. Note: The identifier returned attempts to be unique across network devices but its uniqueness can't be guaranteed.
uuid() (string)
{ since => '4.15', }
t/Venus.t: present: authors t/Venus.t: present: license
166 POD Errors
The following errors were encountered while parsing the POD:
- Around line 23:
Unknown directive: =name
- Around line 31:
Unknown directive: =tagline
- Around line 39:
Unknown directive: =abstract
- Around line 47:
Unknown directive: =includes
- Around line 95:
Unknown directive: =synopsis
- Around line 117:
Unknown directive: =description
- Around line 127:
Unknown directive: =inherits
- Around line 135:
Unknown directive: =integrates
- Around line 145:
Unknown directive: =method
- Around line 150:
Unknown directive: =signature
- Around line 154:
Unknown directive: =metadata
- Around line 236:
Unknown directive: =method
- Around line 241:
Unknown directive: =signature
- Around line 245:
Unknown directive: =metadata
- Around line 327:
Unknown directive: =method
- Around line 331:
Unknown directive: =signature
- Around line 335:
Unknown directive: =metadata
- Around line 357:
=cut found outside a pod block. Skipping to next block.
- Around line 381:
Unknown directive: =method
- Around line 386:
Unknown directive: =signature
- Around line 390:
Unknown directive: =metadata
- Around line 472:
Unknown directive: =method
- Around line 476:
Unknown directive: =signature
- Around line 480:
Unknown directive: =metadata
- Around line 562:
Unknown directive: =method
- Around line 566:
Unknown directive: =signature
- Around line 570:
Unknown directive: =metadata
- Around line 652:
Unknown directive: =method
- Around line 656:
Unknown directive: =signature
- Around line 660:
Unknown directive: =metadata
- Around line 742:
Unknown directive: =method
- Around line 747:
Unknown directive: =signature
- Around line 751:
Unknown directive: =metadata
- Around line 833:
Unknown directive: =method
- Around line 838:
Unknown directive: =signature
- Around line 842:
Unknown directive: =metadata
- Around line 924:
Unknown directive: =method
- Around line 929:
Unknown directive: =signature
- Around line 933:
Unknown directive: =metadata
- Around line 1015:
Unknown directive: =method
- Around line 1022:
Unknown directive: =signature
- Around line 1026:
Unknown directive: =metadata
- Around line 1122:
=cut found outside a pod block. Skipping to next block.
- Around line 1199:
=cut found outside a pod block. Skipping to next block.
- Around line 1275:
=cut found outside a pod block. Skipping to next block.
- Around line 1337:
Unknown directive: =method
- Around line 1342:
Unknown directive: =signature
- Around line 1346:
Unknown directive: =metadata
- Around line 1368:
=cut found outside a pod block. Skipping to next block.
- Around line 1395:
Unknown directive: =method
- Around line 1399:
Unknown directive: =signature
- Around line 1403:
Unknown directive: =metadata
- Around line 1485:
Unknown directive: =method
- Around line 1490:
Unknown directive: =signature
- Around line 1494:
Unknown directive: =metadata
- Around line 1576:
Unknown directive: =method
- Around line 1580:
Unknown directive: =signature
- Around line 1584:
Unknown directive: =metadata
- Around line 1680:
=cut found outside a pod block. Skipping to next block.
- Around line 1756:
=cut found outside a pod block. Skipping to next block.
- Around line 1832:
=cut found outside a pod block. Skipping to next block.
- Around line 1894:
Unknown directive: =method
- Around line 1898:
Unknown directive: =signature
- Around line 1902:
Unknown directive: =metadata
- Around line 1924:
=cut found outside a pod block. Skipping to next block.
- Around line 1986:
Unknown directive: =method
- Around line 1991:
Unknown directive: =signature
- Around line 1995:
Unknown directive: =metadata
- Around line 2077:
Unknown directive: =method
- Around line 2081:
Unknown directive: =signature
- Around line 2085:
Unknown directive: =metadata
- Around line 2103:
=cut found outside a pod block. Skipping to next block.
- Around line 2130:
Unknown directive: =method
- Around line 2135:
Unknown directive: =signature
- Around line 2139:
Unknown directive: =metadata
- Around line 2221:
Unknown directive: =method
- Around line 2226:
Unknown directive: =signature
- Around line 2230:
Unknown directive: =metadata
- Around line 2312:
Unknown directive: =method
- Around line 2316:
Unknown directive: =signature
- Around line 2320:
Unknown directive: =metadata
- Around line 2402:
Unknown directive: =method
- Around line 2406:
Unknown directive: =signature
- Around line 2410:
Unknown directive: =metadata
- Around line 2428:
=cut found outside a pod block. Skipping to next block.
- Around line 2448:
=cut found outside a pod block. Skipping to next block.
- Around line 2469:
=cut found outside a pod block. Skipping to next block.
- Around line 2480:
Unknown directive: =method
- Around line 2484:
Unknown directive: =signature
- Around line 2488:
Unknown directive: =metadata
- Around line 2510:
=cut found outside a pod block. Skipping to next block.
- Around line 2528:
Unknown directive: =method
- Around line 2534:
Unknown directive: =signature
- Around line 2538:
Unknown directive: =metadata
- Around line 2634:
=cut found outside a pod block. Skipping to next block.
- Around line 2710:
=cut found outside a pod block. Skipping to next block.
- Around line 2786:
=cut found outside a pod block. Skipping to next block.
- Around line 2848:
Unknown directive: =method
- Around line 2854:
Unknown directive: =signature
- Around line 2858:
Unknown directive: =metadata
- Around line 2954:
=cut found outside a pod block. Skipping to next block.
- Around line 3030:
=cut found outside a pod block. Skipping to next block.
- Around line 3106:
=cut found outside a pod block. Skipping to next block.
- Around line 3168:
Unknown directive: =method
- Around line 3173:
Unknown directive: =signature
- Around line 3177:
Unknown directive: =metadata
- Around line 3259:
Unknown directive: =method
- Around line 3264:
Unknown directive: =signature
- Around line 3268:
Unknown directive: =metadata
- Around line 3352:
Unknown directive: =method
- Around line 3359:
Unknown directive: =signature
- Around line 3363:
Unknown directive: =metadata
- Around line 3459:
=cut found outside a pod block. Skipping to next block.
- Around line 3535:
=cut found outside a pod block. Skipping to next block.
- Around line 3597:
Unknown directive: =method
- Around line 3602:
Unknown directive: =signature
- Around line 3606:
Unknown directive: =metadata
- Around line 3702:
=cut found outside a pod block. Skipping to next block.
- Around line 3778:
=cut found outside a pod block. Skipping to next block.
- Around line 3854:
=cut found outside a pod block. Skipping to next block.
- Around line 3916:
Unknown directive: =method
- Around line 3923:
Unknown directive: =signature
- Around line 3927:
Unknown directive: =metadata
- Around line 4000:
=cut found outside a pod block. Skipping to next block.
- Around line 4126:
=cut found outside a pod block. Skipping to next block.
- Around line 4188:
Unknown directive: =method
- Around line 4194:
Unknown directive: =signature
- Around line 4198:
Unknown directive: =metadata
- Around line 4243:
=cut found outside a pod block. Skipping to next block.
- Around line 4255:
Unknown directive: =method
- Around line 4261:
Unknown directive: =signature
- Around line 4265:
Unknown directive: =metadata
- Around line 4292:
Unknown directive: =method
- Around line 4298:
Unknown directive: =signature
- Around line 4302:
Unknown directive: =metadata
- Around line 4329:
Unknown directive: =method
- Around line 4334:
Unknown directive: =signature
- Around line 4338:
Unknown directive: =metadata
- Around line 4434:
=cut found outside a pod block. Skipping to next block.
- Around line 4496:
Unknown directive: =method
- Around line 4501:
Unknown directive: =signature
- Around line 4505:
Unknown directive: =metadata
- Around line 4527:
=cut found outside a pod block. Skipping to next block.
- Around line 4544:
Unknown directive: =method
- Around line 4548:
Unknown directive: =signature
- Around line 4552:
Unknown directive: =metadata
- Around line 4634:
Unknown directive: =method
- Around line 4639:
Unknown directive: =signature
- Around line 4643:
Unknown directive: =metadata
- Around line 4665:
=cut found outside a pod block. Skipping to next block.
- Around line 4727:
Unknown directive: =method
- Around line 4732:
Unknown directive: =signature
- Around line 4736:
Unknown directive: =metadata
- Around line 4758:
=cut found outside a pod block. Skipping to next block.
- Around line 4785:
Unknown directive: =method
- Around line 4790:
Unknown directive: =signature
- Around line 4794:
Unknown directive: =metadata
- Around line 4816:
=cut found outside a pod block. Skipping to next block.
- Around line 4843:
Unknown directive: =method
- Around line 4847:
Unknown directive: =signature
- Around line 4851:
Unknown directive: =metadata
- Around line 4933:
Unknown directive: =method
- Around line 4939:
Unknown directive: =signature
- Around line 4943:
Unknown directive: =metadata
- Around line 4965:
=cut found outside a pod block. Skipping to next block.
- Around line 4992:
Unknown directive: =partials