\ -*- mode: forth -*-
\ $Id: random.gforth,v 1.6 2001/06/25 14:20:38 doug Exp $
\ http://www.bagley.org/~doug/shootout/
\ from Jorge Acereda Maciá

0. argc @ 1- arg >number 2drop drop constant NUM

: FIM 1e 139968e f/ POSTPONE FLITERAL ; immediate
: IA 3877 POSTPONE LITERAL ; immediate
: IC 29573 POSTPONE LITERAL ; immediate
: IM 139968 POSTPONE LITERAL ; immediate
42 value seed


: format-float  
  f$ dup >r 0<
  IF    '0 emit
  ELSE  scratch r@ min type  r@ precision - zeros  THEN
  '. emit r@ negate zeros
  scratch r> 0 max /string 0 max -zeros type ;

: gen-random 
    s" seed IA * IC + IM mod dup to seed " evaluate
    s" 0 d>f f* FIM f* " evaluate ; immediate 

: main
    10 SET-PRECISION
    0e NUM 0 do fdrop 100e gen-random loop format-float cr ;

main bye