(*
 * $Id: random.ocaml,v 1.10 2001/07/26 01:33:45 doug Exp $
 * http://www.bagley.org/~doug/shootout/
 * with help from Markus Mottl
 *)

let im = 139968
let ia = 3877
let ic = 29573
let last_ref = ref 42

let gen_random max =
  let new_last = (!last_ref * ia + ic) mod im in
  last_ref := new_last;
  max *. float_of_int new_last /. float im

let _ =
  let n =
    try int_of_string Sys.argv.(1)
    with Invalid_argument _ -> 1 in
  let rec loop i =
    let r = gen_random 100.0 in
    if i > 1 then loop (i-1) else r in
  Printf.printf "%.9f\n" (loop n)