Raja's example is noisy, but it's not white noise. At all.
Your standard white noise is simply a bog-standard random number generator (RNG) producing values at the sampling rate.
If the goal is to get something to a DAC, there are going to have to be some MSP objects involved somewhere down the road (so I don't read the challenge as "no MSP objects allowed", rather as MSP objects being part of Max). So noise~ is the obvious candidate.
Otherwise, you can implement a simple RNG as x[n+1] = a * x[n] + b mod c with arbitrary values for a, b, and c (although the values should be fairly large and, ideally, mutually prime). That is typically used for integer values in a range like 0
Hey. I am looking for the same in pink. That seems a bit more complicated. I know the deviation of the random values must look like a bell curve or one half of it. Can this be done with some math behind a random object.
I think not. I found algorithm examples to generate "pink numbers" in C.
But they use multiple rng to do it. I not fully understand the code example yet. O.
also, since they wrote, "but it’s more for purposes of study than anything else"
it actually sounds like the goal would not necessarily be to get audio to the dac.
x[n+1] = a * x[n] + b mod c
is the answer we ALL needed! :D Thanks!
(when i look through the source for noise~... ooops... i mean... dream of it in my head... ya that's it... i don't still have the source code to max5, don't even think it!... but ya, it looks similar :D
Sorry for any misunderstanding, Raja. But if I misunderstood, others may have, as well.
Regarding the formula I gave: it's a standard formula in the literature (see, for instance, Knuth Art of Computer Programming vol. III). I don't have access to source code for Max, either, but DDZ wrote the the list many years ago that he simply took the RNG from Numerical Recipes in C, which is yet another implementation of the algorithm given by Knuth.
As to pink noise: yes, the samples in pink noise have a Gaussian distribution, but that's not what makes it pink. What makes pink noise "pink" is the correlation between samples.
This is easy to confirm if you have Litter Pro: lp.gsss~ is a plain, uncorrelated Gaussian generator, mainly used for dithering. It actually sounds the same as white noise at audio levels (to the extent that I doubt anyone could reliably tell the difference in A/B tests). The objects lp.sss~ and lp.zzz~ produce pink noise (using two different algorithms, of which lp.zzz~ is generally considered "superior"... James McCartney developed the algorithm used here, so of course it's good!).
You can produce pink noise by filtering white noise, but that's a relatively expensive operation, and it's only an approximation of "real" pink noise. Tim Place wrote an external using this approach, and it uses a third- or fifth-order filter (sorry, forget which). At the time I wrote lp.zzz~ I compared it to Tim's implementation, and the Litter implementation used only about 1/8 of the CPU as the filter approach.
OTOH, the filter approach is pretty easy to write in Max/MSP. Direct generation of correlated samples not so easy (although it might be possible to do something clever by adding a series of square waves at octave intervals, going right up to Nyquist, with the amplitudes set by a RNG).
ah what the heck, below is the max version attached. I wrote the values in a buffer too to look at the buffers spectrum (using the spectrumdraw external from the HIRT) for confirming that it works. cheers!