You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.5 KiB
50 lines
1.5 KiB
#
|
|
# Intent:
|
|
# entropy routines grasping source intention !
|
|
#
|
|
# Note:
|
|
# This work has been done during my time at Doctor I·T
|
|
#
|
|
# -- Copyright drit, 2021 --
|
|
BEGIN { if (-e $ENV{SITE}.'/lib') { use lib $ENV{SITE}.'/lib'; } }
|
|
#
|
|
package seed;
|
|
require Exporter;
|
|
@ISA = qw(Exporter);
|
|
# Subs we export by default.
|
|
@EXPORT = qw();
|
|
# Subs we will export if asked.
|
|
#@EXPORT_OK = qw(nickname);
|
|
@EXPORT_OK = grep { $_ !~ m/^_/ && defined &$_; } keys %{__PACKAGE__ . '::'};
|
|
|
|
use strict;
|
|
use misc qw(version);
|
|
|
|
# The "use vars" and "$VERSION" statements seem to be required.
|
|
use vars qw/$dbug $VERSION/;
|
|
# ----------------------------------------------------
|
|
our $VERSION = sprintf "%d.%02d", q$Revision: 0.0 $ =~ /: (\d+)\.(\d+)/;
|
|
my ($State) = q$State: Exp $ =~ /: (\w+)/; our $dbug = ($State eq 'dbug')?1:0;
|
|
# ----------------------------------------------------
|
|
$VERSION = &version(__FILE__) unless ($VERSION ne '0.00');
|
|
|
|
|
|
sub setseed {
|
|
our $seed = undef;
|
|
# ecf7fa3d : 15min
|
|
$seed = ($_[0]) ? srand($_[0]) : srand();
|
|
printf "seed: %08x\n",$seed;
|
|
return $seed;
|
|
}
|
|
# -----------------------------------------------------------------------
|
|
sub rand64 { # /!\ NOT Cryptographycally safe
|
|
my $i1 = int(rand(0xFFFF_FFFF));
|
|
my $i2 = int(rand(0xFFFF_FFFF));
|
|
my $q = $i1 <<32 | $i2;
|
|
printf "i1: %08x\n",$i1;
|
|
printf "i2: %08x\n",$i2;
|
|
printf "rnd64: %s\n",unpack'H*',pack'Q',$q;
|
|
return $q;
|
|
}
|
|
# -----------------------------------------------------------------------
|
|
1; # $Source: /my/perl/modules/pseudorandom.pm $
|