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

  (provide rand^ rand@)
  (define-signature rand^ [*M31* *P1* rand])
  (define-unit rand@
    (import)
    (export rand^)
    
    (define *M31* 2147483647)    
    (define *P1* 16807)          
    
    (define (rand max seed)
      (let* ((new-seed (remainder (* *P1* seed) *M31*)))
        (remainder new-seed max)))
    
    ;; Providing Scheme's rand allows you to build counterexamples to
    ;; (equal (rand M N) (rand M N))
    #;(define (rand max ignored-seed) ;; ACL2 version uses state-passing
        (random max))
    ))