For more information including compatibility, examples and test cases, see https://github.com/petercrlane/r7rs-libs
SLIB Documentation: http://people.csail.mit.edu/jaffer/slib/Inexact-Random-Numbers.html
0.1. Random Inexact Numbers: (import (slib random-inexact))
A set of functions for generating random inexact numbers. This library is built on top of SRFI 27. All the functions take an optional last argument to define the state. The state is implementation dependent.
The functions all use the default random source, which you can randomise before use using SRFI 27’s:
> (random-source-randomize! default-random-source)
0.1.1. random:exp
random:exp
returns an inexact real in an exponential distribution with mean 1.
sash[r7rs]> (random:exp) 0.34154536262153173 sash[r7rs]> (random:exp) 0.05480703829750473 sash[r7rs]> (random:exp) 3.949150883906155
0.1.2. random:hollow-sphere!
random:hollow-sphere!
fills a given vector with numbers
generated by random:normal
, but ensures the vector is on the n-dimensional
unit sphere, where n is the length of the given vector.
sash[r7rs]> (define v (vector 0 0 0)) #<unspecified> sash[r7rs]> (random:hollow-sphere! v) #t sash[r7rs]> v #(0.15379204615082398 0.8499736823380848 0.5038777092443952) sash[r7rs]> (+ (square (vector-ref v 0)) (square (vector-ref v 1)) (square (vector-ref v 2))) 0.9999999999999999
0.1.3. random:normal
random:normal
returns an inexact real in a normal distribution, mean 0 and
standard deviation 1.
sash[r7rs]> (random:normal) 0.7092759009436378 sash[r7rs]> (random:normal) 1.0895040600796109 sash[r7rs]> (random:normal) -0.03239748330944343
0.1.4. random:normal-vector!
random:normal-vector!
fills a given vector with numbers generated by random:normal
.
sash[r7rs]> (define v (vector 0 0 0)) #<unspecified> sash[r7rs]> (random:normal-vector! v) 1.838805009717658 sash[r7rs]> v #(-0.6720177712702253 -0.9211383829955655 0.7339626722027299)
0.1.5. random:solid-sphere!
random:solid-sphere!
fills a given vector with numbers generated
by random:normal
, but ensures the vector fits within the n-dimensional unit
sphere, where n is the length of the given vector.
sash[r7rs]> (define v (vector 0 0 0)) #<unspecified> sash[r7rs]> (random:solid-sphere! v) 0.810489476742576 sash[r7rs]> v #(-0.7899861662963674 -0.09111554959314132 -0.15656629775645328) sash[r7rs]> (+ (square (vector-ref v 0)) (square (vector-ref v 1)) (square (vector-ref v 2))) 0.6568931919104545
0.1.6. random:uniform
random:uniform
is the same as SRFI 27’s random-real
, and returns
a uniformly distributed inexact number in the range (0,1).
sash[r7rs]> (random:uniform) 0.7868209548678019 sash[r7rs]> (random:uniform) 0.2504803406880286