Bytes::Random - Perl extension to generate random bytes.


Bytes-Random documentation Contained in the Bytes-Random distribution.

Index


Code Index:

NAME

Top

Bytes::Random - Perl extension to generate random bytes.

SYNOPSIS

Top

  use Bytes::Random;

  my $bytes = random_bytes( $number_of_bytes );

DESCRIPTION

Top

Bytes::Random provides the random_bytes($num) function. It can be used anytime you need to generate a string of random bytes of a specific length.

EXPORT

random_bytes( $number_of_bytes )

Returns a string containing as many random bytes as was requested.

AUTHOR

Top

John Drago, <jdrago_999@yahoo.com>

COPYRIGHT AND LICENSE

Top


Bytes-Random documentation Contained in the Bytes-Random distribution.

package Bytes::Random;

use 5.006000;
use strict;
use warnings;
use bytes;

require Exporter;

our @ISA = qw(Exporter);

our @EXPORT = qw(
	random_bytes
);

our $VERSION = '0.02';


#==============================================================================
sub random_bytes
{
  my $number = shift;
  return '' unless $number > 0;
  
  my @out = ( );
  for( 1..$number )
  {
    my $rand = int( rand() * 256 );
    push @out, chr( $rand );
  }# end for()
  
  return join '', @out;
}# end random_bytes()

1;# return true: