Sound.SC3.Lang.Random.Gen

Description

`RandomGen` based `sclang` random number functions.

Synopsis

Documentation

rand :: (RandomGen g, Random n, Num n) => n -> g -> (n, g)Source

`SimpleNumber.rand` is `randomR` in (0,n).

kvariant :: Int -> (g -> (a, g)) -> g -> ([a], g)Source

Construct variant of f generating k values.

nrand :: (RandomGen g, Random n, Num n) => Int -> n -> g -> ([n], g)Source

Variant of `rand` generating k values.

rand2 :: (RandomGen g, Random n, Num n) => n -> g -> (n, g)Source

`SimpleNumber.rand2` is `randomR` in (-n,n).

nrand2 :: (RandomGen g, Random a, Num a) => Int -> a -> g -> ([a], g)Source

Variant of `rand2` generating k values.

rrand :: (Random n, RandomGen g) => n -> n -> g -> (n, g)Source

`SimpleNumber.rrand` is `curry` `randomR`.

nrrand :: (RandomGen g, Random a, Num a) => Int -> a -> a -> g -> ([a], g)Source

Variant of `rrand` generating k values.

choose :: RandomGen g => [a] -> g -> (a, g)Source

`SequenceableCollection.choose` selects an element at random.

nchoose :: RandomGen g => Int -> [a] -> g -> ([a], g)Source

Variant of `choose` generating k values.

exprand :: (Floating n, Random n, RandomGen g) => n -> n -> g -> (n, g)Source

`SimpleNumber.exprand` generates exponentially distributed random number in the given interval.

nexprand :: (Floating n, Random n, RandomGen g) => Int -> n -> n -> g -> ([n], g)Source

Variant of `exprand` generating k values.

coin :: (RandomGen g, Random a, Ord a, Fractional a) => a -> g -> (Bool, g)Source

`SimpleNumber.coin` is `True` at given probability, which is in range (0,1).

ncoin :: (RandomGen g, Random a, Ord a, Fractional a) => Int -> a -> g -> ([Bool], g)Source

Variant of `coin` generating k values.

``` fst (ncoin 5 0.5 (mkStdGen 0)) == [True,True,False,True,False]
```

scramble :: RandomGen g => [t] -> g -> ([t], g)Source

`List.scramble` shuffles the elements.

``` fst (scramble [1..5] (mkStdGen 0)) == [1,5,2,3,4]
```

windex :: (Ord a, Num a) => [a] -> a -> Maybe IntSource

`ArrayedCollection.windex` takes a list of probabilities, which should sums to n, and returns the an index value given a (0,n) input.

``` map (windex [0.1,0.3,0.6]) [0,0.1 .. 0.4] == [Just 0,Just 1,Just 1,Just 1,Just 2]
```

wchoose :: (RandomGen g, Random a, Ord a, Fractional a) => [b] -> [a] -> g -> (b, g)Source

`SequenceableCollection.wchoose` selects an element from a list given a list of weights which sum to `1`.