Data-Rand

 view release on metacpan or  search on metacpan

lib/Data/Rand.pm  view on Meta::CPAN

        my ($length) = @_;
        return Crypt::Random::makerandom_itv( 'Lower' => 0, 'Upper' => $length, ...); 
    }

Note: The above example (w/ Strong => 0 (IE read() is not being blocked on /dev/random)) benchmarked appx 570 times as slow as the default L<rand>() based solution but its much more truly random.

=back

=back

=head2 rand_data_string()

Same args as rand_data(). The difference is that it always returns a string regardless of context.

    my $rand_str = rand_data_string( @rand_args ); # $rand_str contains the random string.
    my @stuff    = rand_data_string( @rand_args ); # $stuff[0] contains the random string.

=head2 rand_data_array()

Same args as rand_data(). The difference is that it always returns an array regardless of context.

    my @rand_data = rand_data_array( @rand_args ); # @rand_data contains the random items
    my $rand_data = rand_data_array( @rand_args ); # $rand_data is an array ref to the list of random items

=head2 seed_calc_with()

This is a simple shortcut function you can use to call L<srand>() for you with a pre-done calculation as outlined below. If this does not do what you like use L<srand>() directly.

It brings in L<Time::HiRes> for you if needed and then calls L<srand>() like so:

    srand($hires_time, $hires_micro_seconds, $$, 'YOUR ARGUEMENT HERE' || rand( 999_999_999_999_999));

You don't have to call it of course but here are some examples if you choose to:

    seed_calc_with();                                  # same as seed_calc_with( rand( 999_999_999_999_999 ) );
    seed_calc_with( rand( 999_999_999_999_999 ) );     # same as seed_calc_with();
    seed_calc_with( unpack '%L*', `ps axww | gzip` );
    seed_calc_with( Math::TrulyRandom::truly_random_value() );
    seed_calc_with( Crypt::Random::makerandom(...) ); 

Its not exportable on purpose to discourage blindly using it since calling L<srand>() improperly can result in L<rand>()'s result being less random.

See L<srand> and L<rand> for more information.

=head1 DIAGNOSTICS

Throws no warnings or errors of its own.

=head1 CONFIGURATION AND ENVIRONMENT
  
Data::Rand requires no configuration files or environment variables.

=head1 DEPENDENCIES

L</seed_calc_with>() brings in L<Time::HiRes>

=head1 INCOMPATIBILITIES

None reported.

=head1 BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to
C<bug-data-rand@rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org>.

=head1 TODO

Re-add tests I had worked up that went away with a failed HD

May add these behaviorial booleans to option hashref depending on feedback:

    'return_on_bad_args' # do not use defaults, just return;
    'carp_on_bad_args'   # carp() about what args are bad and why
    'croak_on_bad_args'  # same as carp but fatal

Gratefully apply helpful suggestions to make this module better

=head1 AUTHOR

Daniel Muey  C<< <http://drmuey.com/cpan_contact.pl> >>

=head1 LICENCE AND COPYRIGHT

Copyright (c) 2007, Daniel Muey C<< <http://drmuey.com/cpan_contact.pl> >>. All rights reserved.

This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic>.

=head1 DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.



( run in 0.882 second using v1.01-cache-2.11-cpan-39bf76dae61 )