Note: This is taken from the Chicken Wiki, where a more recent version could be available.
(use syntax-case gsl-srfi-27) (import gsl-srfi-27) (random-real) ; => some random real number (random-source-randomize! default-random-source) (random-integer 100) ; => some integer between 0 and 99 (inclusive)
You can also use some of the simulation-quality generators from the GSL:
(use syntax-case gsl-srfi-27) (import gsl-srfi-27) (let* ((luxury-source (make-random-source *ranlxd2*)) ; Ahhh---what a luxurious generator (luxury-real (random-source-make-reals luxury-source))) (random-source-randomize! luxury-source) ; Don't forget this, or you won't experience true luxury (luxury-real)) ;; A *very* random number.
Written by Will M. Farr.
Released under the GPL.
Requires the eggs syntax-case and easyffi.
In addition to the routines from SRFI-27, after issuing (import gsl-srfi-27) the following will be available in the namespace:
[rng-type] *mt19937* [rng-type] *ranlxd1* [rng-type] *ranlxd2* [rng-type] *cmrg* [rng-type] *mrg* [rng-type] *taus* [rng-type] *taus2* [rng-type] *gfsr4*
A subset of the GSL simulation-quality generator types, suitable to pass to (make-random-source TYPE). Don't accept anything less than a simulation-quality generator!
[procedure] (rng-type? OBJ)
#f unless OBJ is one of the above generator types.
The gsl-srfi-27 egg does not completely conform to the SRFI-27 standard: (random-source-make-reals SOURCE [UNIT]) throws an error if the UNIT parameter is passed instead of generating a random source with the given quantization.