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

  (provide teachpack^ teachpack@)
  (define-signature teachpack^ [*M31* *P1* rand])
  (define-unit teachpack@
    (import)
    (export teachpack^)
    
    (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))
    ))