Hi there:
Out of curiosity, I thought I will take a look at how [noise~] is implemented. While knowing just enough C to write little externals, I am a bit puzzled at the method in which the random number is obtained in here as I only know of rand() method in ANSI C. I also looked at the code for [random] and they look similar. Homebrew?
I wonder if anyone could provide some comments on the code or explain a little so that I can know how it works.
static t_int *noise_perform(t_int *w) { t_float *out = (t_float *)(w[1]); int *vp = (int *)(w[2]); int n = (int)(w[3]); int val = *vp; while (n--) { *out++ = ((float)((val & 0x7fffffff) - 0x40000000)) * (float)(1.0 / 0x40000000); val = val * 435898247 + 382842987; } *vp = val; return (w+4); }
Many thanks
Yours
CHUN
static t_int *noise_perform(t_int *w) { t_float *out = (t_float *)(w[1]); int *vp = (int *)(w[2]); int n = (int)(w[3]);
getting arguments ...
int val = *vp;
setting seed
while (n--) {
looping over the dsp block
*out++ = ((float)((val & 0x7fffffff) - 0x40000000)) * (float)(1.0 / 0x40000000);
scaling the random number between -1 and 1
val = val * 435898247 + 382842987;
generating new random number
} *vp = val;
dont forget it
return (w+4);
}
done ...
if you are interested in different noise generators most of the noise generators from supercollider (quite a log actually) are part of sc4pd ... an sc header file contains the inline functions for the rngs ...
cheers ... tim
Hi there:
Thanks for your comments:)
static t_int *noise_perform(t_int *w) { t_float *out = (t_float *)(w[1]); int *vp = (int *)(w[2]); int n = (int)(w[3]);
getting arguments ...
int val = *vp;
setting seed
while (n--) {
looping over the dsp block
*out++ = ((float)((val & 0x7fffffff) - 0x40000000)) * (float)(1.0 / 0x40000000);
scaling the random number between -1 and 1
Ummmm, I don't quite understand this scaling code, especially with the long numbers. Is this like the fast way of doing scaling? Like doing bit shifting is fast multiplying?
val = val * 435898247 + 382842987;
generating new random number
This is the bit that I really like to learn, you can get random number by adding two large numbers times the seed? Also how does the seeding method works?
static int init = 307; x->x_val = (init *= 1319);
} *vp = val;
dont forget it
return (w+4);
}
done ...
if you are interested in different noise generators most of the noise generators from supercollider (quite a log actually) are part of sc4pd ... an sc header file contains the inline functions for the rngs ...
Cool, I will look into that. I don't know of sc4pd, what is it? I did wonder why supercollider is in Pd's CVS. Does sc4pd allows you to do/script/run supercollider in Pd?
Many thanks again
CHUN
if you are interested in different noise generators most of the noise generators from supercollider (quite a log actually) are part of sc4pd... an sc header file contains the inline functions for the rngs ...
Cool, I will look into that. I don't know of sc4pd, what is it? I did wonder why supercollider is in Pd's CVS. Does sc4pd allows you to do/script/run supercollider in Pd?
a port of sc ugens to flext ...
on sourceforge ... t
Hi Chun,
It's a simple, homebrew pseudo-random number generator. I'm not sure where you can find the theory of pseudorandom number generators, but basically the val = val * 435898247 + 382842987 step mixes up the set of odd 32-bit integers in a very complicated way.
cheers Miller
On Fri, Oct 22, 2004 at 12:28:11AM +0100, chun lee wrote:
Hi there:
Out of curiosity, I thought I will take a look at how [noise~] is implemented. While knowing just enough C to write little externals, I am a bit puzzled at the method in which the random number is obtained in here as I only know of rand() method in ANSI C. I also looked at the code for [random] and they look similar. Homebrew?
I wonder if anyone could provide some comments on the code or explain a little so that I can know how it works.
static t_int *noise_perform(t_int *w) { t_float *out = (t_float *)(w[1]); int *vp = (int *)(w[2]); int n = (int)(w[3]); int val = *vp; while (n--) { *out++ = ((float)((val & 0x7fffffff) - 0x40000000)) * (float)(1.0 / 0x40000000); val = val * 435898247 + 382842987; } *vp = val; return (w+4); }
Many thanks
Yours
CHUN
PD-dev mailing list PD-dev@iem.at http://iem.at/cgi-bin/mailman/listinfo/pd-dev
It's a simple, homebrew pseudo-random number generator. I'm not sure where you can find the theory of pseudorandom number generators,
nummerical recipes in c ... the pdf's are online ...
but basically the val = val * 435898247 + 382842987 step mixes up the set of odd 32-bit integers in a very complicated way.
as described in nr as "an even quicker generator" ...
cheers ... tim
On 25/10/04 10:08 am, "Tim Blechmann" TimBlechmann@gmx.net wrote:
It's a simple, homebrew pseudo-random number generator. I'm not sure where you can find the theory of pseudorandom number generators,
nummerical recipes in c ... the pdf's are online ...
Found it, thanks!
but basically the val = val * 435898247 + 382842987 step mixes up the set of odd 32-bit integers in a very complicated way.
as described in nr as "an even quicker generator" ...
unfortunately, I am having a fever with splitting headache at the moment, so it might take me a while to get through it.
Apologies for opened up 2 thread on Pd's RNG questions..
Cheers
CHUN
Hi miller:
Thanks for your reply, I found the links below in implementing the minimal standard/Lehmer RNG.
http://www.sbc.su.se/~per/crng/seminar/rng5.html http://www.cs.virginia.edu/~jcc5t/classes/undergrad/simulation/random/rng.c
In addition, what is the period of the homebrew method? Also, are the large numbers 435898247, 382842987 specifically chosen or they works as long as they a sufficiently large?
Cheers
CHUN
On 25/10/04 5:00 am, "Miller Puckette" mpuckett@man104-1.ucsd.edu wrote:
Hi Chun,
It's a simple, homebrew pseudo-random number generator. I'm not sure where you can find the theory of pseudorandom number generators, but basically the val = val * 435898247 + 382842987 step mixes up the set of odd 32-bit integers in a very complicated way.
cheers Miller
On Fri, Oct 22, 2004 at 12:28:11AM +0100, chun lee wrote:
Hi there:
Out of curiosity, I thought I will take a look at how [noise~] is implemented. While knowing just enough C to write little externals, I am a bit puzzled at the method in which the random number is obtained in here as I only know of rand() method in ANSI C. I also looked at the code for [random] and they look similar. Homebrew?
I wonder if anyone could provide some comments on the code or explain a little so that I can know how it works.
static t_int *noise_perform(t_int *w) { t_float *out = (t_float *)(w[1]); int *vp = (int *)(w[2]); int n = (int)(w[3]); int val = *vp; while (n--) { *out++ = ((float)((val & 0x7fffffff) - 0x40000000)) * (float)(1.0 / 0x40000000); val = val * 435898247 + 382842987; } *vp = val; return (w+4); }
Many thanks
Yours
CHUN
PD-dev mailing list PD-dev@iem.at http://iem.at/cgi-bin/mailman/listinfo/pd-dev
Also cool and very light is the mersenne twister. http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
Chris.
On Mon, Oct 25, 2004 at 12:03:45PM +0100, chun lee wrote:
Hi miller:
Thanks for your reply, I found the links below in implementing the minimal standard/Lehmer RNG.
http://www.sbc.su.se/~per/crng/seminar/rng5.html http://www.cs.virginia.edu/~jcc5t/classes/undergrad/simulation/random/rng.c
In addition, what is the period of the homebrew method? Also, are the large numbers 435898247, 382842987 specifically chosen or they works as long as they a sufficiently large?
Cheers
CHUN
On 25/10/04 5:00 am, "Miller Puckette" mpuckett@man104-1.ucsd.edu wrote:
Hi Chun,
It's a simple, homebrew pseudo-random number generator. I'm not sure where you can find the theory of pseudorandom number generators, but basically the val = val * 435898247 + 382842987 step mixes up the set of odd 32-bit integers in a very complicated way.
cheers Miller
On Fri, Oct 22, 2004 at 12:28:11AM +0100, chun lee wrote:
Hi there:
Out of curiosity, I thought I will take a look at how [noise~] is implemented. While knowing just enough C to write little externals, I am a bit puzzled at the method in which the random number is obtained in here as I only know of rand() method in ANSI C. I also looked at the code for [random] and they look similar. Homebrew?
I wonder if anyone could provide some comments on the code or explain a little so that I can know how it works.
static t_int *noise_perform(t_int *w) { t_float *out = (t_float *)(w[1]); int *vp = (int *)(w[2]); int n = (int)(w[3]); int val = *vp; while (n--) { *out++ = ((float)((val & 0x7fffffff) - 0x40000000)) * (float)(1.0 / 0x40000000); val = val * 435898247 + 382842987; } *vp = val; return (w+4); }
Many thanks
Yours
CHUN
PD-dev mailing list PD-dev@iem.at http://iem.at/cgi-bin/mailman/listinfo/pd-dev
PD-dev mailing list PD-dev@iem.at http://iem.at/cgi-bin/mailman/listinfo/pd-dev
------------------- chris@mccormick.cx http://mccormick.cx