NAME

Data::Random::Flexible - Flexible fast-to-write profilable randoms

VERSION

Version 1.05

SYNOPSIS

A more flexible set of randoms for when you want to be random FAST

use Data::Random::Flexible;

use feature "say";

my $random = Data::Random::Flexible->new();

say "32 Characters of random numbers?, sure: ".$random->int(32);

say "16 Characters of random letters?, sure: ".$random->char(16);

say "16 Of a mixture of numbers and letters?, sure: ".$random->mix(16);

say "Random mixture of 16 your own characters?, sure: ".$random->profile('irc',16, [qw(I r C 1 2 3)]);

say "Random mixture of 16 your own characters from a saved profile?, sure: ".$random->profile('irc',16);

The module can also use alternative providers for rand(), for more detail look at the engine() function, the currently supported providers of random are:

Math::Random::Secure
Math::Random::MTwist
Math::Random::Xorshift
Math::Random::MT
Math::Random::ISAAC
Math::Random::ISAAC::XS (Not selectable will be used AUTO if availible by Math::Random::ISAAC)
Crypt::PRNG
Your own code reference.

new()

Create a new Math::Random::Flexible object, accepts 1 optional argument, a hashref of profiles

engine()

Return a list of availible engines for rand(), by default the module will always use CORE::rand, that being perls inbuilt rand. If you want to change it simply provide your choice as the first argument.

If you pass in a reference to your own random function it will attempt a test against it if successful it will use that!

An example of passing your own:

sub mycode { return int(rand(9)) }

$random->engine(\&mycode);

If you pass something weird that is not a known engine or a reference, it will not switch engines but will raise a warning.

NOTE Normal every day users just wanting a nice way to get random numbers and such of a set length need not pay attention to it!

store()

Set and/or return the stored profiles, will always return the currently used profiles, unless you pass it something it did not expect as a first argument, where it will return a blank hashref.

alpha()

Return a random alpha character uppercase or lowercase, accepts 1 argument 'length', if length is ommited return a single alpha-char;

char()

Though technically wrong, it is a shorthand to alpha()

numeric()

Return a random whole number, accepts 1 argument 'length', if length is ommited return a single number.

int()

A shorthand for numeric()

alphanumeric()

Return a random alphanumeric string, accepts 1 argument 'length', if length is ommited return a single random alpha or number.

mix()

A shorthand for alphanumeric()

profile()

Set or adjust a profile of characters to be used for randoms, accepts 3 arguments in the following usages:

Create or edit a profile named some_name and return a 16 long string from it

$random->profile('some_name',16,[qw(1 2 3)]);

Return 16 chars from the pre-saved profile 'some_name'

$random->profile('some_name',16);

Delete a stored profile

$random->profile('some_name',0,[]);

AUTHOR

Paul G Webster, <daemon at cpan.org>

BUGS

Please report any bugs to: https://github.com/PaulGWebster/p5-Data-Random-Flexible

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc p5::Data::Random::Flexible

You can also look for information at:

LICENSE AND COPYRIGHT

Copyright 2017 Paul G Webster.

This program is distributed under the (Revised) BSD License: http://www.opensource.org/licenses/BSD-3-Clause

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

* Neither the name of Paul G Webster's Organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.