fork download
  1. \ http://e...content-available-to-author-only...a.com/sphinx/article-xorshift.html
  2.  
  3. variable seed
  4. utime seed !
  5.  
  6. : random ( -- x ) \ return a 32-bit random number x
  7. seed @
  8. dup 13 lshift xor
  9. dup 17 rshift xor
  10. dup 5 lshift xor
  11. dup seed !
  12. ;
  13.  
  14. : setseed ( x -- ) \ seed the RNG with x
  15. dup 0= or \ map 0 to -1
  16. seed !
  17. ;
  18.  
  19. random 10 mod 1+ . \ random number [1, 10]
  20.  
Success #stdin #stdout 0s 6824KB
stdin
Standard input is empty
stdout
9