Forums > MaxMSP

Random float

February 11, 2008 | 5:13 pm

Hallo Max Users,

I wonder if you could give me a tip how to get a random float, as I could not use the object random, it is only good for integers.

Thank you!
tedor


February 11, 2008 | 5:19 pm

multiply by 0.0001
or
beter still
use Ranf http://www.timara.oberlin.edu/~gnelson/maxdownloads/downloadmax.htm


February 11, 2008 | 5:52 pm

Ohhh, yes I should use my brain sometimes…. I am going to see whats on the site…

thank you!


February 11, 2008 | 6:05 pm

The scale object is one option to make your integer into a float.
Another is simply to do your own scale operation using multiply and
divide. You’ll need float arguments for any of these to work.

On Feb 11, 2008, at 10:13 AM, tedor wrote:

>
> Hallo Max Users,
>
> I wonder if you could give me a tip how to get a random float, as I
> could not use the object random, it is only good for integers.

—-
Steven M. Miller
Professor, Contemporary Music Program
College of Santa Fe

Home < http://pubweb.csf.edu/~smill>
SFIFEM <
http://sfifem.csf.edu>
Atrium Sound Space <
http://atrium.csf.edu>
OVOS <
http://pubweb.csf.edu/~smill/ovos.html>
CMP <
http://www.csf.edu/academics/contemporary_music/>


February 12, 2008 | 9:51 pm

tedor schrieb:
> I wonder if you could give me a tip how to get a random float, as I
> could not use the object random, it is only good for integers.

was it yesterday? we just had some solutions floating around here… ;-)

To contribute a bit more, the other thread inspired me to make a little
quasi gaussian random generator by summing 4 random values:

save as qgauss:

#P window setfont "Sans Serif" 9.;
#P window linecount 2;
#P message 56 96 20 196617 set 0;
#P window linecount 1;
#P newex 79 70 24 196617 b;
#P newex 79 96 50 196617 uzi 4;
#P newex 56 150 56 196617 accum;
#P window linecount 2;
#P newex 79 117 61 196617 random 536870912;
#P window linecount 1;
#P newex 254 72 22 196617 t 1;
#P newex 254 93 48 196617 gate 2 2;
#P newex 204 121 23 196617 + 1;
#P newex 204 93 48 196617 route int;
#P newex 167 68 47 196617 zl slice 1;
#P newex 167 47 62 196617 patcherargs;
#P outlet 56 195 15 0;
#P inlet 292 47 15 0;
#P inlet 143 47 15 0;
#P inlet 79 49 15 0;
#P newex 56 172 155 196617 scale 0 2147483644 $1 $2;
#P connect 3 0 9 1;
#P connect 10 0 9 0;
#P connect 7 0 10 0;
#P fasten 9 0 8 0 259 115 209 115;
#P connect 7 0 8 0;
#P connect 6 1 7 0;
#P fasten 8 0 0 4 209 167 177 167;
#P fasten 7 1 0 4 247 167 177 167;
#P fasten 9 1 0 4 297 167 177 167;
#P connect 5 0 6 0;
#P connect 2 0 0 3;
#P connect 6 0 0 3;
#P connect 11 0 12 1;
#P connect 13 0 11 0;
#P connect 14 0 13 0;
#P connect 1 0 14 0;
#P connect 0 0 4 0;
#P connect 12 0 0 0;
#P connect 13 1 12 0;
#P connect 15 0 12 0;
#P fasten 14 1 15 0 98 91 61 91;
#P window clipboard copycount 16;

save as qgauss.help

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 209 74 50 196617 uzi 3000;
#N vtable 128 434 413 646 592 5 128;
#P newobj 209 206 39 196617 table;
#P newex 209 183 39 196617 histo;
#P newex 209 122 61 196617 qgauss 127;
#P message 272 75 29 196617 clear;
#P button 72 52 15 0;
#P newex 72 75 50 196617 uzi 400;
#N vtable 12 280 413 420 590 980005 100;
#P newobj 72 206 39 196617 table;
#P newex 72 183 39 196617 histo;
#P flonum 138 148 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 138 122 68 196617 qgauss -1. 1.;
#P button 72 98 15 0;
#P number 84 149 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 72 122 61 196617 qgauss 12;
#P window linecount 2;
#P comment 108 27 171 196617 quasi gaussian random generator. Its just
the sum of 4 randoms…;
#P connect 9 0 8 0;
#P fasten 9 0 14 0 77 71 214 71;
#P fasten 9 0 10 0 77 71 277 71;
#P connect 12 1 13 1;
#P connect 12 0 13 0;
#P fasten 10 0 6 0 277 177 77 177;
#P fasten 10 0 12 0 277 177 214 177;
#P connect 11 0 12 0;
#P connect 14 0 11 0;
#P connect 4 0 5 0;
#P connect 3 0 1 0;
#P fasten 3 0 4 0 77 117 143 117;
#P connect 6 1 7 1;
#P connect 1 0 6 0;
#P connect 1 0 2 0;
#P connect 6 0 7 0;
#P connect 8 0 3 0;
#P window clipboard copycount 15;


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com


February 12, 2008 | 10:36 pm

looks weird, but where can I find the qguass object to let it run?

or is one of them the object itself which then i need to copy in one of the Max/Msp folders?

thx


February 13, 2008 | 8:48 am

tedor schrieb:
> looks weird, but where can I find the qguass object to let it run?

I posted it into the message, copy the part below "save as qgauss:" till
"save as qgauss.help", paste it into an empty max window or choose past
from clipboard. Save as qgauss.mxb. then copy the part below "save as
qgauss.help" and paste from clipboard. Thats the help patch to it. Or
wait till I upload an update to my St.ools… ;-)

You can also use Peter Castines objects, which are externals as opposed
to an abstraction, they are more effective and precise… But I usually
prefer simple over correct… ;-)

Stefan


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com


February 13, 2008 | 8:51 pm

Danke Stefan,

It works now, by coincidence I used the extension ‘mxo’ first.. it was working with that as well… it is strange… where can you use this object? As I think the "multiply by 0.0001" is easy…

how comes that you programed this object?

thx

tedor


February 13, 2008 | 9:55 pm

Frankly, I would us lp.shhh from Litter Power.

It provides better resolution than multiplying random by 0.0001 or any other small fraction, as well as using a more industrial-strength algorithm for generating random values.

Lp.shhh is included in the free Litter Starter Pack. This is currently PPC-only in the Mac world, but as indicated in my recent announcement < http://www.bek.no/~pcastine/Press/>, this is not a permanent state of affairs. Windows users never had to worry about this issue, anyway.


February 13, 2008 | 10:41 pm

Summing four uniformly distributed values for a pseudo-Gaussian… well, OK…

You really ought to sum at least a dozen independent uniforms to approximate a Gauss distribution. Using 12 has the advantage that you automatically get a convenient standard deviation.

However, it still not a true Gaussian distribution. The "tails" at the extreme ends are cut off. To get a real Gauss ditribution you need, by definition, to add an infinite number of uniform random values. That takes a while.-)

You might want to look at the patch implementing a Gaussian distribution in Classic Litter < http://www.bek.no/~pcastine/Litter/>, which implements the Box-Muller formula. This gives a real Gaussian distribution in finite time.

Both of the above approaches still have real performance issues. The current versions of Litter Power and, even more importantly, Litter Bundle for Jitter use more advanced algorithms and will give you far more random number bang for your CPU buck.

Best,
Peter


February 14, 2008 | 8:29 pm

Quote: tedor wrote on Mon, 11 February 2008 09:13
—————————————————-

> I wonder if you could give me a tip how to get a random float, as I could not use the object random, it is only good for integers.
>

—————————————————-

just another way:

http://cnmat.berkeley.edu/patch/4023

mz


February 17, 2008 | 1:18 pm

thank you all for the help,
I have got an Intel Mac, so some will not work on mine:)
There is some much about randomness, I can not believe it!
all the best!


February 24, 2008 | 8:35 am

tedor schrieb:
> how comes that you programed this object?

You just inspired me to do it… ;-)

Peter Castine schrieb:
> You really ought to sum at least a dozen independent uniforms to
> approximate a Gauss distribution. Using 12 has the advantage that you
> automatically get a convenient standard deviation.

Yes, I realised that 2 would give me a triangle and visually I couldn’t
see much difference between 4 and more…

> However, it still not a true Gaussian distribution. The "tails" at
> the extreme ends are cut off.

But in practice I never want a true gaussian, I usually want it cut off…

And thanks a lot for the clarification, I just love your knowledge…

It still holds that if you want it correct, use Peters objects, but it
is helpful to create your own silly version, in the end you get all the
information missing in the Litter help… ;-)

Peter you should write a random book for Maxers, I’d buy it…

Stefan


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com


Viewing 13 posts - 1 through 13 (of 13 total)