Function
(ran{keyword value}*)
Generates random numbers in a variety of distributions according to its keyword arguments.
ran supports the following keyword arguments:
:below number:from number:type:uniform.
ran supports the following distribution types:
:uniform:low-pass:high-pass:mean:beta:exponential:a parameter is a stretching factor;
increasing its value "prefers" smaller numbers. The distribution is
unbounded but when a=1 then %99.9 of the time the value returned
will be than 6.9077554, i.e. -log(.001). The distribution density is
f(x)=(exp -x) with a mean of 1.0.
:gaussian:cauchy:poisson:a controls the
distribution's shape and must be positive: the mean is a and the
standard deviation is sqrt(a).
:gamma:a controls the distribution's shape and
should be a positive integer (if a non-integer is provided, the
value is rounded.) When a=1, the distribution is the same as
exponential. As its value increases, the probability density
function becomes a curve with mean=a and standard deviation =
sqrt(a)
:a number:b number:state state*random-state*.
;; The ran function. (define (play-ran type len rate key1 key2) (process repeat len for r = (ran :type type) for k = (rescale r 0.0 1.0 key1 key2) output (new midi :time (now) :keynum k :duration (* rate 1.5)) wait rate)) ;;; Playing uniform distribution. (events (play-ran ':uniform 100 .1 20 100) "test.mid" :channel-tuning 4) ⇒ "test.mid" ;;; Playing the low pass distribution. (events (play-ran ':low 50 .1 20 100) "test.mid" :channel-tuning 4) ⇒ "test.mid" ;;; Playing the high pass distribution. (events (play-ran :high 50 .1 20 100) "test.mid" :channel-tuning 4) ⇒ "test.mid" ;; The beta distribution. (define (rain len rate env key1 key2 amp) (process for i below len for e = (interpl (/ i len) env) for v = (vary rate e :above) ;; rescale e to control shape of beta distribution ;; when e=0 z=.4, and when e=1 z=1. for z = (rescale e 0 1 1 .4) for b = (ran :type ':beta :a z :b z) output (new midi :time (+ (now) v) :duration v :keynum (between key1 key2) :amplitude (rescale b 0 1 .1 amp)) wait rate)) (define rain-env '(0 1 .4 0 .6 0 1 1)) (events (list (rain 80 .5 rain-env 70 90 .8) (rain 40 1 rain-env 40 60 .8) (rain 20 2 rain-env 20 40 .9)) "test.mid") ⇒ "test.mid"