Welcome to the CHICKEN Scheme pasting service

Gauche's implementation (in math.mt-random) added by sjamaan on Sun Nov 5 20:59:42 2017

(define (%get-nword-random-int mt n)
  (let loop ((i 0) (r (%mt-random-uint32 mt)))
    (if (= i n)
        r
        (loop (+ i 1)
              (+ (ash r 32) (%mt-random-uint32 mt))))))

(define (mt-random-integer mt n)
  (when (not (positive? n)) (error "invalid range" n))
  (if (<= n #x100000000)
      (%mt-random-integer mt n)
      (let* ((siz (ash (integer-length n) -5))
             (q   (quotient (ash 1 (* 32 (+ siz 1))) n))
             (qn  (* q n)))
        (let loop ((r (%get-nword-random-int mt siz)))
          (if (< r qn)
              (quotient r q)
              (loop (%get-nword-random-int mt siz)))))))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Which one-argument R5RS procedure returns 2 when given `'(1 2 3)' as input?
Visually impaired? Let me spell it for you (wav file) download WAV