Forums > MaxMSP

Negative random number


Jul 16 2013 | 2:37 pm

How do I create a negative random number?

I am looking to create a random integer number between -1 and 1, so the values would be -1, 0 and 1.
I am having trouble figuring out how to do this.
Any help would be great!

Thanks
Neil

Jul 16 2013 | 2:55 pm
<code>
-- Pasted Max Patch, click to expand. --

</code>

Jul 16 2013 | 5:00 pm

That’s a very neat solution, thank you!

Jul 16 2013 | 5:36 pm

[expr (random(0\,2))-1]

Jul 16 2013 | 9:58 pm

Mike S, your solution for float can’t reach one (or it’s too early in the morning for me…).

Jul 16 2013 | 9:58 pm

Mike S, your solution for float can’t reach 1.0 (or it’s too early in the morning for me…).
edit : hiccup, double post sorry

Jul 17 2013 | 7:28 am
<code>
-- Pasted Max Patch, click to expand. --

</code>

Jul 17 2013 | 3:53 pm

here you go:

— Pasted Max Patch, click to expand. —
Jul 18 2013 | 4:30 am

@ barry, is this more efficient than subtraction? ie. mike s’ solution for integer?

Jul 18 2013 | 5:44 am

No idea I’m afraid…

Jul 18 2013 | 7:18 am

Hi Stephan,

Change the random object to 201, then it will reach 1.

Jul 19 2013 | 2:51 am

@Woyteg: In general, fewer objects means less overhead.

Also: subtraction is (at least in principle) always more efficient than branching ("if" logic), and [gate] presumably is based on "if" logic. However, when patching in Max, the overhead for message-passing is several orders of magnitude higher than the difference between subtraction and branching at the machine level. So this is something you really don’t need to lose sleep over.

What bothers me more about Mike’s (float) solution is the granularity of the output. This may not matter in a lot of applications, but if your set up is such that different things happen for 0.0, 0.005, and 0.01; well, 0.005 isn’t going to happen in this patch. You can work around that, of course, following Chris’ example of higher granularity. You simply have to know what you want and how to get it.

For my part, I’d use lp.shhh and take the 24-bit granularity and run with it. At this point in time with Max 6 (and unfortunately), that is only an option for people using Litter Power Pro. Working on this, though.

Jul 19 2013 | 4:09 pm

i dont think 5 objects are more effective than 1 or 2.
but i still like his solution. it had to be added here for the sake of completeness, and hopefully some expansion of conciousness.

and where you need only 2 values there is the good old [chance] object, which could trigger two sexy [zl reg] to store and trigger anything you like.

-110

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

Forums > MaxMSP