teachpacks/rand.scm
(module rand mzscheme
  (require (lib "unit.ss"))

  (provide teachpack^ teachpack@)

  (define-signature teachpack^
    [*M31* *P1* seedp initial-seed next-seed rand])

  (define-unit teachpack@
    (import)
    (export teachpack^)
    
    (define *M31* 2147483647)
    (define *P1* 16807)

    (define seedp integer?)

    (define (initial-seed) 1382728371)

    (define (next-seed seed)
      (remainder (* *P1* seed) *M31*))
    
    (define (rand max seed)
      (remainder seed max)))

  )