How to RANDOMIZE floating point numbers?

azahn123's icon

I was wondering if there is anyway to tell random to accept floating point numbers? Or is this a custom thing that can be done with other objects? I found a JAVA thingy to make this happen... BUT is there any standard way to do this with the standard MAX objects?
An example of code would be greatly appreciated. - Andrew.

Andrew Pask's icon
Max Patch
Copy patch and select New From Clipboard in Max.
azahn123's icon

THANKS ! But how to control the range of the randomization ?

Peter Nyboer's icon
Max Patch
Copy patch and select New From Clipboard in Max.

scale object? I prefer this way, since I may not want DSP involved:

Chris Muir's icon
Max Patch
Copy patch and select New From Clipboard in Max.

I use this abstraction called RandomRangeFloat

jvkr's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Or a really slow version,

Peter Castine's icon

Or, a really fast version: Litter Power , for instance [lp.shhh~] -> [lp.scampf].

Orkester's icon

wouldn't this do it? Maybe I'm missing something, seems pretty simple.

Max Patch
Copy patch and select New From Clipboard in Max.

Chris Muir's icon

@Orkester – it all depends on the definition of "range." I use a fairly similar approach above, but it is extended to allow for independent lower and upper bounds.

Chris Muir's icon

@Peter – I can't believe I missed this opportunity to plug Litter Power.

Yoann's icon
midinerd's icon

TLDR: [random LARGEST_INTEGER_ALLOWED] -> [/. LARGEST_INTEGER_ALLOWED] -> [zmap 0. 1. destination_min destination_max]

That should give you the highest resolution floating point value, where you supply zmap your min/max destination ranges.

The above is based on this:
[random] has a seed message you can send to select given pre-created random walks.
Not sure what the default is (when you provide it no seed 1,2,3 etc. message) perhaps it is 0.
I believe those random walks are looking up buffers of floating-point value data.

[random] likely starts as floating-point numbers in the background, then scales them up based on the integer argument you provide in [random X].

You can verify this by setting the [random 10] seed value with a message of say "seed 1", step through and look at the values
then by setting the [random 100] seed value with a message of say "seed 1", step through and look at the values, they should be suspiciously close to the original [random 10] series but scaled up by a factor of 10 and with the added precision of calculating the added placeholder. in other words you're bringing out detail by allowing the resolution of [random] to flow through 100 slots instead of just 10.

So the real question is: what is the highest range [random] provides?
Then: [random HIGHEST_VALUE] -> [/. HIGHEST_VALUE] = {floating point 0.-1.} -> [zmap 0. 1. destination_min_range

If I'm right in my assumptions, you'll get the original value of the point from the pre-existing random/seed buffer that it's reading from.

cheers

Roman Thilenius's icon

back in the days the random object was using the random number generation from your apple computer hardware.

it might be that it is using rdrand without scaling on intel, but i doubt that floating numbers can be the origin of something :)

Augustine Bannatyne - Leudar's icon

Couldnt you just do it with integers and then divide by 10/100/1000/100000 whatever ?

Christopher Dobrian's icon

I didn't do a survey of all the previous answers, so this may repeat some of what's offered above.

This abstraction allows you to specify a range using the @minimum and @maximum attributes, and a number of evenly-distributed possibilities within that range using the @possibilities attribute. By default, it gives you 1,000,001 possibilities in the range from 0 to 1. If, for example, you asked for 1,001 possibilities in the range 100 to 200, you would get all the possible numbers that have 1 decimal place within that range.

Max Patch
Copy patch and select New From Clipboard in Max.