Jump to content

Pseudo-random numbers/Xorshift star: Difference between revisions

m
→‎{{header|Factor}}: call it by its true name >:)
m (→‎{{header|Factor}}: call it by its true name >:))
Line 86:
<lang factor>USING: accessors kernel literals math math.statistics
prettyprint sequences ;
IN: rosetta-code.xorshift-star
 
CONSTANT: mask64 $[ 1 64 shift 1 - ]
Line 92 ⟶ 91:
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 ;
Line 103 ⟶ 102:
state<< const * mask64 bitand -32 shift mask32 bitand ;
 
: next-float ( obj -- xn ) next-int 1 32 shift /f ;
 
! ---=== Task ===---
1234567 <xorshift-star*> 5 [ dup next-int . ] times
 
987654321 >>state
1,827

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.