% $Id: random.slang,v 1.0 2003/01/03 13:41:00 dada Exp $
% http://dada.perl.it/shootout/
%
% contributed by John E. Davis

variable IM = 139968;
variable IA = 3877;
variable IC = 29573;
variable LAST = 42;

define gen_random(max)
{
    LAST = (LAST * IA + IC) mod IM;
    (max * LAST) / IM;
}

define main()
{
   variable N = integer (__argv[1]);
   if (N < 1)
     N = 1;

   loop (N-1)
     () = gen_random (100.0);

   vmessage ("%.9f", gen_random(100.0));
}

main();