Pseudo-random numbers/Xorshift star: Difference between revisions
Pseudo-random numbers/Xorshift star (view source)
Revision as of 00:11, 19 January 2021
, 3 years ago→{{header|Perl}}: made Xorshift_star a real class, allowing the creation of multiple objects with different states
SqrtNegInf (talk | contribs) (Added Perl) |
m (→{{header|Perl}}: made Xorshift_star a real class, allowing the creation of multiple objects with different states) |
||
Line 447:
use Math::AnyNum qw(:overload);
my ($class, %opt) = @_;
}
sub next_int {
my ($self) = @_;
my $state = $self->{state};
$state ^= $state >> 12;
$state ^= $state << 25 & (2**64 - 1);
$state ^= $state >> 27;
($state * 0x2545F4914F6CDD1D) >> 32 & (2**32 - 1);
}
}
say 'Seed: 1234567, first 5 values:';
my $rng = Xorshift_star->new(
say
my %h;
say "\nSeed: 987654321, values histogram:";
$rng = Xorshift_star->new(
$h{
say "$_ $h{$_}" for sort keys %h;</lang>
{{out}}
|