[Function]
(ransegs len {keyword value}*)

Returns a list of len number of random segments from a specified distribution type. Segment values are either sample points or increments between points in the distribution. If points are returned they are sorted lowest to highest.

ransegs supports the following keyword arguments:

:type keyword
The type of random distribution to sample points from. The default type is :uniform. See documentation on ran for more information.
:sum number
If this argument is specified then the function returns increments between sample points in the distribution and the segments are scaled so that they sum to number. If this argument is not specified then sample points, rather than increments, are returned.
:min number
The minimum value to return from the distribution. The default value is 0.0.
:max number
The maximum value to return from the distribution. The default value is 1.0.
:a number
A parameter whose meaning depends on the distribution type. See documentation on ran for more information.
:b number
A parameter whose meaning depends on the distribution type. See documentation on ran for more information.

The :sum argument cannot be specified if either :min or :max appear as arguments to the function.

Examples:

Example 1. The ransegs function.

(ransegs 5 :min 2 :max 4)
 (2 2.2559445 3.4245749 3.7436724 4)
(ransegs 5 :max 10 :type ':high-pass)
 (0.0 7.4660807 8.559072 9.499652 10)
(ransegs 5 :sum 10 :type ':high-pass)
 (5.330133 0.32402468 1.5141625 1.9792953 0.85238457)
(ransegs 5 :min -10 :max 10 :type ':mean)
 (-10 -5.596928 1.3310728 7.758129 10)

Example 2. High pass segments for increasing rain drops.

(define (rainy-play len tot lb ub)
  (let ((segs (ransegs len :sum tot :type ':high-pass)))
    (process for i from 0
             for s in segs
             unless (= i 0)
             output
             (new midi :time (now)
                  :amplitude (interp i 0 .2 len .7)
                  :duration (between .1 .25)
                  :keynum (between lb ub))
             wait s
             finally
             (output (new midi :time (now)
                          :duration .35
                          :amplitude .8
                          :keynum (pick ub (- ub 5) lb))))))
                
(events (list (rainy-play 30 20 84 96)
              (rainy-play 30 20 72 84)
              (rainy-play 30 20 60 72)
              (rainy-play 30 20 48 60))
        "test.mid")
 "test.mid"

See also: