View Single Post
Old 09-01-2009, 06:30 PM   #22
Human being with feelings
liteon's Avatar
Join Date: Apr 2008
Posts: 510
Default methods of pseudo-random number generation with non-uniform distribution

explained below is a method for generating white noise with non-uniform distribution.

unlike the gaussian function for white gaussian noise this method uses trigonometric functions and in general can be tweaked to produce quick variations in regard of probability density with relatively fast execution times.

you may have stumbled on this before doing a simple oscillator:
//full code
this recursion algorithm is a prng with non-uniform (trigonometric) distribution which outputs in the [-1,+1] range for y using sin(), previous value y[n-1] and an 'index' variable x.

probability density function:
sin() will result in a 'negative' pdf function (less density in center ), while tan() in positive.

execution times:
-slower than the above park–miller and faster than rand() (but both implementations are uniform).
-using tan() is slower than sin(), and tan() requires limiting and some tweaks.

use of approximations:
-example link with some approximations for trigonometric functions at musicdsp -

plot for tan() - scaled:

extra points for guessing why the @gfx sections outputs the exponential grid.

plotter algorithm:

short read on trigonometry in non-uniform distributions:


Last edited by liteon; 09-01-2009 at 07:30 PM.
liteon is offline   Reply With Quote