Pseudo-random numbers/Xorshift star: Difference between revisions

Add Factor
m (→‎{{header|Raku}}: Separate BUILD and TWEAK is overkill for this instance)
(Add Factor)
Line 82:
* Show your output here, on this page.
 
 
=={{header|Factor}}==
<lang factor>USING: accessors kernel literals math math.statistics
prettyprint sequences ;
IN: rosetta-code.xorshift-star
 
CONSTANT: mask64 $[ 1 64 shift 1 - ]
CONSTANT: mask32 $[ 1 32 shift 1 - ]
CONSTANT: const 0x2545F4914F6CDD1D
 
TUPLE: xorshift-star state ;
 
: <xorshift-star> ( seed -- xorshift-star )
mask64 bitand xorshift-star boa ;
 
: twiddle ( m n -- n ) dupd shift bitxor mask64 bitand ;
 
: next-int ( obj -- n )
dup state>> -12 twiddle 25 twiddle -27 twiddle tuck swap
state<< const * mask64 bitand -32 shift mask32 bitand ;
 
: next-float ( obj -- n ) next-int 1 32 shift / ;
 
! ---=== Task ===---
1234567 <xorshift-star> 5 [ dup next-int . ] times
 
987654321 >>state
100,000 [ dup next-float 5 * >integer ] replicate nip
histogram .</lang>
{{out}}
<pre>
3540625527
2750739987
4037983143
1993361440
3809424708
H{ { 0 20103 } { 1 19922 } { 2 19937 } { 3 20031 } { 4 20007 } }
</pre>
 
=={{header|Go}}==
1,827

edits