Pseudo-random numbers/Xorshift star: Difference between revisions

m
→‎{{header|Raku}}: further simplification and in-lining
m (→‎{{header|Raku}}: simplify, remove some superstitious parenthesis, only mask when necessary)
m (→‎{{header|Raku}}: further simplification and in-lining)
Line 381:
has $!state;
 
submethod BUILD ( Int :$seed where * > 0 = 1 ) { $!state = $seed +& mask64 }
constant mask64 = 2⁶⁴ - 1;
constant const = 0x2545F4914F6CDD1D;
 
submethod BUILD ( Int :$seed where * > 0 = 1 ) { $!state = $seed +& mask64 }
 
method next-int {
$!state +^= $!state +> 12;
$!state +^= $!state +< 25 +& mask64(2⁶⁴ - 1);
$!state +^= $!state +> 27;
($!state * const0x2545F4914F6CDD1D) +> 32 +& (2³² - 1)
}
 
method next-rat { self.next-int / 2³² }
}
 
 
# Test next-int
10,327

edits