lalo ·
Any algorhythm to do it in the audio , integer and float realms?
with a min. max. range too 🙂
thanx
lalo
From the original SynthMaker forum (2004–2014), with its members’ names and dates.
lalo ·
Any algorhythm to do it in the audio , integer and float realms?
with a min. max. range too 🙂
thanx
lalo
Shifrin ·
You could have a look here :-
http://en.wikipedia.org/wiki/Linear_congruential_generator
Shif.
lalo ·
thanx shif...i'll do... welcome back man 🙂
lalo ·
http://www-personal.engin.umich.edu/~wa ... eTwister.h
😮
would be nice to have a module for this algo.....transferring it to the code component seems a pain in the ass...is just a pain in the ass to read the actual c code 🙂
infact a rnd generator with inlets for min and max values would be nice either in the float/integer and sample rate realms 🙂
i tried the stuff at the link shif posted....kind of it works with integer values.... but seems to stay in a pretty limited range
lalo
Shifrin ·
Interesting stuff lalo, I've read about the Mersenne Twister before but that's some good sources to play with 😉
The algo. on the page I posted is OK for a pseudo-random number generator :-
rand_n+1 = [rand_n*1664525 + 1013904223] mod 4294967296
It will produce numbers in the range 0 .. 4294967295, so you can get floats in the range 0.0 .. 1.0 by dividing by 4294967295. Or scale however you wish 🙂
I may have a go at implementing one or two of the algos in the sources you posted the link to if I get some time later 🙂
Shif.
lalo ·
Shifrin wrote: Interesting stuff lalo, I've read about the Mersenne Twister before but that's some good sources to play with 😉
The algo. on the page I posted is OK for a pseudo-random number generator :-
rand_n+1 = [rand_n*1664525 + 1013904223] mod 4294967296
It will produce numbers in the range 0 .. 4294967295, so you can get floats in the range 0.0 .. 1.0 by dividing by 4294967295. Or scale however you wish 🙂
I may have a go at implementing one or two of the algos in the sources you posted the link to if I get some time later 🙂
Shif.
thanx shif...i was trying with far simpler coefficients 🙂
lalo
infuzion ·
I had this sitting on my HD for 3 months... guess it's time to release it: http://rapidshare.de/files/5502260/Rand ... r.osm.html (open the link in a new tab/window, scroll to the bottom, then click on {Free}. The link will be on the bottom of the new page. Will expire after no downloading for 3 weeks.) old version
The first trigger will output only the 1st Float, & uses less CPU. The second trigger will give 2 outputs, & the first will be more random. Mix & match triggering for more random fun! I suggest triggering a few or few dozen times yourselves before saving to HD, adding to tool box etc, since it really only plays a numbered sequence; keeps outputs from being the same. The GUI is a bit silly, but hey, you can pick it out in a schematic instantly 🙂
Realease licence: free, but if you use it, please give NUmber & myself a copy of works that use it. cheers
sambean ·
Nice one Infuzion, one to add to the toolkit..
Here's my own little pseudo random number generator I have based on a similar method to what Shif describes..
Not sure how random it really is..
http://freespace.virgin.net/cc.lai/tool ... Number.osm
It has two different ways in which it can be used..
The first method is for just plain old sequncial random numbers:
Set seed to anything you want between 0 and 1, Set index to 1, Press trigger to generate the random numbers (these will be the same every time you use it, but different for every seed..), With this method changing the seed will reset the generator.
The second method can be used for generating random numbers that need to be the same each time they are used..
For each random parameter you need to have a separate module, Give each module a unique index (0, 1, 2, ...), Control the input to the seed connections with one parameter, Different seed values will give you a differerent random number from each module, Choosing the same seed value will give you the same random numbers you had before..
I use the second method for designing different 'rooms' on my reverb.. the seed is the room ID and the random numbers control the delay lengths..
Tom7777 ·
Its always interesting finding various different ways to create random numbers 🙂 My Algorithmic synth uses similar methods for creating random numbers. Making true random numbers is something quite hard to do as theres always a type of sequence to it.
skOre ·
And maybe its about not making it too random?
I think that one should really play around in this domain, searching for musical outcome, rather than mathmatical correctness!
stefan ·
There's no way to generate "true" random numbers, so don't worry too much about it 🙂 Any mathematical random number generator will be deterministic (and I almost dare to say that any other is as well, but you might get upset with me 🙂)
Tom7777 ·
I guess you could create some complex AI system but even then it would still be following certain processes and patterns, i don't think anyone should get upset by you saying that as like you say there is no true random, when you spin a dice it has a certain amount of rolls to it depending on the angle and speed it starts from, you could use mathmatics to emulate this but even then its still not true random.
skOre ·
Well, I think that stefan is right... as long as we have no means to emulate stuff down to a quantum level (which should be pretty impossible imho), we will never get close to the randomness of nature.
Tom7777 ·
Speaking of randomness in nature i hear that every snowflake is of a different pattern, but im not sure if that is true as im sure there must have been ones of the same type before. 🙂
stefan ·
skOre wrote: Well, I think that stefan is right... as long as we have no means to emulate stuff down to a quantum level (which should be pretty impossible imho), we will never get close to the randomness of nature.
OT: I daresay that everything at the quantum level is determnistic as well, it's just that it's impossible to measure 🙂
skOre ·
stefan wrote: skOre wrote: Well, I think that stefan is right... as long as we have no means to emulate stuff down to a quantum level (which should be pretty impossible imho), we will never get close to the randomness of nature.
OT: I daresay that everything at the quantum level is determnistic as well, it's just that it's impossible to measure 🙂
Some say (well, Heisenberg to be exact), that if you do measure it (which is quite possible afaik), you only get one or the other half of what you want, but never the full thing.
stefan ·
skOre wrote: stefan wrote: skOre wrote: Well, I think that stefan is right... as long as we have no means to emulate stuff down to a quantum level (which should be pretty impossible imho), we will never get close to the randomness of nature.
OT: I daresay that everything at the quantum level is determnistic as well, it's just that it's impossible to measure 🙂
Some say (well, Heisenberg to be exact), that if you do measure it (which is quite possible afaik), you only get one or the other half of what you want, but never the full thing.
Well, he also states the size of the error of the measure. What I meant was that it isn't possible to measure it correctly/exact/etc. We can't do measurements at the quantum level without actually messing up the actual system and hence measurement, but that doesn't in any way mean that quantum physics aren't deterministic. It just means that we can't determine these systems 🙂
GaryG ·
sounds like SM needs a Heisenberg Compensator module...
😉
skOre ·
Heh, yeah. That would certainly rock. SM: to the skies!
Shifrin ·
Back on topic 😉
This will produce a chaotic output :-
streamin seed; streamout out;
stage(0) { out = seed; } stage(1) { out = 2.0*out*out - 1.0; }
Shif.
infuzion ·
Tom7777 wrote: Speaking of randomness in nature i hear that every snowflake is of a different pattern, but im not sure if that is true as im sure there must have been ones of the same type before. 🙂
so, all you have to do is read the snowflake patterns for a seed value 😉
but seriously two things: 1) The best way to find how random an algorithm is to graph 1000 or so itterations of the generator(s) IMHO
2) perhaps the best way is to have random primitives? Machine code would be speeder I'd assume.
Tom7777 ·
Shifrin i just tried to use your code example but got no audio output, how would i use this code?
Shifrin ·
Tom7777 wrote: Shifrin i just tried to use your code example but got no audio output, how would i use this code?
Yeah, I just remembered, if you're trying to get this to produce output when playing a controller, like a normal osc, you need to create a 'dummy streamin' and connect the 'freq' (or any other I think) output from a MidiToPoly module to this dummy streamin - that will make the code run when a note is played.
Shif.
Tom7777 ·
Ok thanks Shifrin 🙂
sambean ·
Hey Folks,
Just come up with this compact noise generator algo, thought it may be useful..
streamin seed; streamout out; float sign; float rand;
stage(0) {
// //Seed has to be between 0 and 1 //Fop some reason (seed % 1) //doesn't seem to work.. //
rand = seed + 0.000001; // stops stable values eg 0.5 rand = min(rand , 0.9999); // 1 and 0 are both stable too.. rand = max(rand , 0.0001);
}
stage(1) {
// // Optimised pseudo random number // rand = ( rand * 3 ) % 1 //
rand = rand*3; rand = rand - (rand>2)&1; rand = rand - (rand>1)&1;
out = rand*2 - 1;
}
Any comments, let me know..
🙂
Sam
Kingston ·
Hi all. thought I'd share this,
very optimised pink noise generator based on sambeans example and this: http://www.firstpr.com.au/dsp/pink-noise/
The last multiplication is just gain obviously. do whatever you want with it.
This seems to work fine on any samplerate.
streamout out; float b0,b1,b2,tmp,rand=0.600001;
stage(0) {rand=rand;} stage(1) { rand = rand*3; rand = rand - (rand>2)&1; rand = rand - (rand>1)&1; tmp = rand*2 - 1;
b0 = 0.99765 * b0 + tmp * 0.0990460; b1 = 0.96300 * b1 + tmp * 0.2965164; b2 = 0.57000 * b2 + tmp * 1.0526913; tmp = b0 + b1 + b2 + tmp; }
out=tmp* 0.00001;
sambean ·
And here's some quick code for brown/red noise...
streamout out; streamin step; streamin leak;
float b0,b1,b2,tmp,rand=0.600001;
stage(0) {rand=rand;} stage(1) { rand = rand*3; rand = rand - (rand>2)&1; rand = rand - (rand>1)&1; tmp = rand*2 - 1;
red = red*leak + step * tmp;
}
Which is basically the random value integrated over time with a leaky coefficient giving you constrained brownian motion/random walk..
It's useful for adding a slight continous randomness to a parameter.. I use it for the lfo for the red choir chorus
Leak should be a value like 0.999, and step something small like 0.001
Kingston ·
Hey thanks!
Looks to be more efficient than my version as well, and surely capable of pink noise, if I understood it right.
Cheers sambean.
[EDIT]
Hmm, can't seem to get it to output anything but whitenoise. What's that variable 'red' referrring to anyway?
Tom7777 ·
Nice, thanks Sambean 😀
lalo ·
thanx guys....que viva open source 🙂 😉
lalo
sambean ·
Ahhh, the 'red' is supposed to be the streamout.. If you analyse the output, it should look like a 'random walk' ie each consecutive sample is within the range +/- step of the previous sample.. In the freq domain it should look like -6dB/octave lowpassed filtered white noise as the signal is being integrated.. I'm not sure if it's usable as pink noise which is supposed to be -3dB/octave..
You have to tweak the step and leak parameters to make sure the range is generally limited to +/-1.
I havn't been able to check the code as I'm at work..
sambean ·
here's some 'pink' resources
http://www.firstpr.com.au/dsp/pink-noise/
There's an interesting part about using bandpassed pink noise in the <20Hz range as a control source.. If I'm getting it right, by adjusting the fc of the bandpass you can adjust the 'frequency' of the random fluctuations, and as the noise is pink they will have the same RMS level...
Sam
Kingston ·
stupido me,
minor errors. here's a corrected one.
monoout out; float b0,b1,b2,tmp,rand=0.600001;
stage(0) {rand=rand;} stage(1) { rand = rand*3; rand = rand - (rand>2)&1; rand = rand - (rand>1)&1; tmp = rand*2 - 1;
b0 = 0.99765 * b0 + tmp * 0.0990460; b1 = 0.96300 * b1 + tmp * 0.2965164; b2 = 0.57000 * b2 + tmp * 1.0526913; out = b0 + b1 + b2 + tmp * 0.1848; }
by the way sambean, this pink noise is based on the http://www.firstpr.com.au/dsp/pink-noise/ example: 'economy' version with accuracy of +/-0.5dB.
I didn't bother with the more accurate one as it uses about double the CPU, and in my use the difference inaudible.
Tom7777 ·
Thanks 😀
oddson ·
How do I make magenta noise? 😈
skOre ·
Well, given that magenta is pretty much pink... 😉
Or you could mix some of the other Colors of noise 😇
oddson ·
How about a brown note?
The Sound Scientist ·
lol..... My buddies and I have made jokes about that before.....ahhahah 😀
sambean ·
oddson wrote: How about a brown note?
heheheh.. I think thats why they choose to call brownian noise 'red noise' too, to avoid confusion.. If I had called my chorus 'Brown choir', I don't think it would have had the same ring to it..
luisi ·
sambean,
just used your module to release the schematic of a prorietaty effect
http://www.kvraudio.com/forum/viewtopic ... 79#1932079
schematic without the NUSofting fractal LFO, replaced with your random generator: http://www.dashsignature.com/SM/Modisma ... al_LFO.osm
sambean wrote: Nice one Infuzion, one to add to the toolkit..
Here's my own little pseudo random number generator I have based on a similar method to what Shif describes..
Not sure how random it really is..
http://freespace.virgin.net/cc.lai/tool ... Number.osm
It has two different ways in which it can be used..
The first method is for just plain old sequncial random numbers:
Set seed to anything you want between 0 and 1, Set index to 1, Press trigger to generate the random numbers (these will be the same every time you use it, but different for every seed..), With this method changing the seed will reset the generator.
The second method can be used for generating random numbers that need to be the same each time they are used..
For each random parameter you need to have a separate module, Give each module a unique index (0, 1, 2, ...), Control the input to the seed connections with one parameter, Different seed values will give you a differerent random number from each module, Choosing the same seed value will give you the same random numbers you had before..
I use the second method for designing different 'rooms' on my reverb.. the seed is the room ID and the random numbers control the delay lengths..
adamszabo ·
infuzion, do you still have your dual float random generator somewhere?
infuzion ·
adamszabo wrote: infuzion, do you still have your dual float random generator somewhere?
Yes, but it has been superseded by SM's Random Number since that can seed of the CPU clock, so it is much more random. You may need to fraction-multiply to get the correct ratio.
tor ·
I made this for my EQ:
streamin in; streamin noiseamp; streamout out;
float noise; float mem[165481]= rand(1,-1); float index=0;
noise = mem[index];
index = index+1; index = index-(index >= 165481) & 165481;
out = in+(noise*noiseamp);
Andrew J ·
Can't remember if I've posted this elsewhere, but here's some optimised ASM for a Park-Miller PRNG with with n=65537 and g=75. Bring on the white noise!
streamout out; float seed=1;float g=75;float F1=1; float n=65537;float nRcp=1.52585562e-005; movaps xmm0,seed;mulps xmm0,g;movaps seed,xmm0; fld n[0];fld seed[0];fprem;fstp seed[0];fstp st(0); //fld n[1];fld seed[1];fprem;fstp seed[1];fstp st(0); //fld n[2];fld seed[2];fprem;fstp seed[2];fstp st(0); //fld n[3];fld seed[3];fprem;fstp seed[3];fstp st(0); movaps xmm0,seed; mulps xmm0,nRcp;addps xmm0,xmm0;subps xmm0,F1; movaps out,xmm0;
adamszabo ·
Andrew J wrote: Can't remember if I've posted this elsewhere, but here's some optimised ASM for a Park-Miller PRNG with with n=65537 and g=75. Bring on the white noise!
Thank but how do you use this? for me it doesnt seem to do anything. Does it have a trigger or something?
Andrew J ·
It's set up as a free running mono audio source at the moment. I can rewrite it for keying pretty easily, but you might have to wait till I get home!
Andrew J ·
If you want to key the white noise, then use the following ASM in a module with poly in/outs.
streamin key; streamout out; float seed=1;float g=75;float F1=1; float n=65537;float nRcp=1.52585562e-005; movaps xmm0,seed;mulps xmm0,g;movaps seed,xmm0; fld n[0];fld seed[0];fprem;fstp seed[0];fstp st(0); fld n[1];fld seed[1];fprem;fstp seed[1];fstp st(0); fld n[2];fld seed[2];fprem;fstp seed[2];fstp st(0); fld n[3];fld seed[3];fprem;fstp seed[3];fstp st(0); movaps xmm0,seed; mulps xmm0,nRcp;addps xmm0,xmm0;subps xmm0,F1; movaps out,xmm0;
Note that channels 2-4 have now been uncommented.
infuzion ·
Andrew J wrote: If you want to key the white noise, then use the following ASM in a module with poly in/outs.
I thought white noise was pitchless?
Andrew J ·
infuzion wrote: Andrew J wrote: If you want to key the white noise, then use the following ASM in a module with poly in/outs.
I thought white noise was pitchless?
Yeah, but you can still key it on and off...
MegaHurtz ·
Anyone know a good close to infinite white noise gen?
Andrew J ·
MegaHurtz wrote: Anyone know a good close to infinite white noise gen?
The one I've posted above is the best I can do for now. Can't do rand31-park-miller-carta without some more integer opcodes for ASM...
MichaelBenjamin ·
what also helps with all kinds of digital noise is to nest/interleave several processes, like for example take andrews code and feed the result in that other rand31 code from this thread to replace a static. or get some suitable green random number for andrews codes statics. also iterations/feedback can be used to further bend the noise.
Wrote something here? To have a post removed or your name hidden, write to [email protected].