Negative random number

    Jul 16 2013 | 9: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!

    • Jul 16 2013 | 9:55 pm
    • Jul 17 2013 | 12:00 am
      That's a very neat solution, thank you!
    • Jul 17 2013 | 12:36 am
      [expr (random(0\,2))-1]
    • Jul 17 2013 | 4:58 am
      Mike S, your solution for float can't reach one (or it's too early in the morning for me...).
    • Jul 17 2013 | 4:58 am
      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 | 2:28 pm
    • Jul 17 2013 | 10:53 pm
      here you go:
    • Jul 18 2013 | 11:30 am
      @ barry, is this more efficient than subtraction? ie. mike s' solution for integer?
    • Jul 18 2013 | 12:44 pm
      No idea I'm afraid...
    • Jul 18 2013 | 2:18 pm
      Hi Stephan,
      Change the random object to 201, then it will reach 1.
    • Jul 19 2013 | 9: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 | 11: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.