Pseudo-random numbers/Xorshift star: Difference between revisions
Pseudo-random numbers/Xorshift star (view source)
Revision as of 16:42, 14 August 2020
, 3 years ago→{{header|Raku}}: simplify, remove some superstitious parenthesis, only mask when necessary
(→{{header|Factor}}: restrict seed to positive integers) |
Thundergnat (talk | contribs) m (→{{header|Raku}}: simplify, remove some superstitious parenthesis, only mask when necessary) |
||
Line 376:
{{trans|Python}}
Raku does not have unsigned Integers at this time (Integers are arbitrary sized) so use explicit bit masks during bitwise operations. All constants are encapsulated inside the class.
<lang perl6>class Xorshift-star {
has $!state;
constant mask64 = 2⁶⁴ - 1;
constant const = 0x2545F4914F6CDD1D;
submethod BUILD ( Int :$seed where * > 0 = 1 ) {
method next-int {
$!state +^=
$!state +^=
$!state +^=
}
|