Negative random number

Jul 16, 2013 at 2:37pm

Negative random number

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

#256215
Jul 16, 2013 at 2:55pm

<code>

– Pasted Max Patch, click to expand. –

</code>

#256220
Jul 16, 2013 at 5:00pm

That’s a very neat solution, thank you!

#256236
Jul 16, 2013 at 5:36pm

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

#256237
Jul 16, 2013 at 9:58pm

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

#256244
Jul 16, 2013 at 9:58pm

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

#256245
Jul 17, 2013 at 7:28am

<code>

– Pasted Max Patch, click to expand. –

</code>

#256280
Jul 17, 2013 at 3:53pm

here you go:

– Pasted Max Patch, click to expand. –
#256327
Jul 18, 2013 at 4:30am

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

#256359
Jul 18, 2013 at 5:44am

No idea I’m afraid…

#256361
Jul 18, 2013 at 7:18am

Hi Stephan,

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

#256366
Jul 19, 2013 at 2:51am

@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.

#256445
Jul 19, 2013 at 4:09pm

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

#256533

You must be logged in to reply to this topic.