View Single Post
Old 09-01-2009, 06:30 PM   #22
liteon
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:
Code:
//full code
@init
x=y=1;
@sample
y=sin((x+=1)*y);
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 - http://musicdsp.org/files/approx.h

plot for tan() - scaled:


vid:
https://stash.reaper.fm/oldsb/618700/...tribution0.gif
extra points for guessing why the @gfx sections outputs the exponential grid.

plotter algorithm:
https://stash.reaper.fm/oldsb/618769/prngplot

short read on trigonometry in non-uniform distributions:
http://www.stat.wisc.edu/~larget/math496/random2.html



------
lubomir

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