12345678910111213141516171819202122232425262728293031 |
- (define-module (random))
- (use-modules
- ;; SRFI-27 for random number utilities
- (srfi srfi-27))
- (define-public make-random-integer-generator
- (lambda* (#:key seed)
- "Get a procedure for generating uniformly distributed
- random integers from 0 up to a not included bound, which is
- seeded by the keyword argument seed, which must be a
- positive integer."
- (cond
- [seed
- (let ([rand-src (make-random-source)])
- ;; Set the given seed to guarantee same results for
- ;; same invokations.
- (random-source-pseudo-randomize! rand-src 0 seed)
- ;; Obtain a procedure, which gives uniformly
- ;; distributed integers.
- (random-source-make-integers rand-src))]
- [else
- (let ([rand-src (make-random-source)])
- ;; Try to make the random source truly random. How
- ;; this works depends on the specific implementation
- ;; of SRFI-27.
- (random-source-randomize! rand-src)
- (random-source-make-integers rand-src))])))
|