Crypt::Random::Source::Weak::rand - Use C<rand> to create random bytes


Crypt-Random-Source documentation Contained in the Crypt-Random-Source distribution.

Index


Code Index:

NAME

Top

Crypt::Random::Source::Weak::rand - Use rand to create random bytes

SYNOPSIS

Top

    use Crypt::Random::Source::Weak::rand;

    my $p = Crypt::Random::Source::Weak::rand->new;

    $p->get(1024);

DESCRIPTION

Top

This is a weak source of random data, that uses Perl's builtin rand function.

METHODS

Top

seed @blah

Sets the random seed to a checksum of the stringified values of @blah.

There is no need to call this method unless you want the random sequence to be identical to a previously run, in which case you should seed with the same value.

get $n

Produces $n random bytes.

AUTHOR

Top

  Yuval Kogman <nothingmuch@woobling.org>

COPYRIGHT AND LICENSE

Top


Crypt-Random-Source documentation Contained in the Crypt-Random-Source distribution.

package Crypt::Random::Source::Weak::rand;
BEGIN {
  $Crypt::Random::Source::Weak::rand::AUTHORITY = 'cpan:NUFFIN';
}
BEGIN {
  $Crypt::Random::Source::Weak::rand::VERSION = '0.07';
}
# ABSTRACT: Use C<rand> to create random bytes

use Any::Moose;

use bytes;

extends qw(
    Crypt::Random::Source::Weak
    Crypt::Random::Source::Base
);

sub rank { -100 } # slow fallback

sub available { 1 }

sub seed {
    my ( $self, @args ) = @_;
    srand( unpack("%L*", @args) );
}

sub get {
    my ( $self, $n ) = @_;
    pack "C*", map { int rand 256 } 1 .. $n;
}

1;




# ex: set sw=4 et:

__END__