tests/python/common/src/random.python

#!/usr/local/bin/python
# $Id: random.python,v 1.2 2003/12/30 01:22:55 davidw Exp $
# http://www.bagley.org/~doug/shootout/
# with help from Brent Burley

# END COMMENT
import sys

IM = 139968
IA = 3877
IC = 29573

LAST = 42
def gen_random(max):
    global LAST
    LAST = (LAST * IA + IC) % IM
    return( (max * LAST) / IM )

def main():
    N = int(sys.argv[1])
    if N < 1:
        N = 1
    gr = gen_random
    for i in xrange(1,N):
        gr(100.0)
    print "%.9f" % gr(100.0)

main()

Generated by GNU enscript 1.6.3.