## Random Range

Jul 8, 2009 at 5:23pm

# Random Range

I’m sure that this must be within the tutorials somewhere, but I can’t seem to locate it.

Using the [random] object, how do you set it so that only a number within a specific range is output post-bang?

The tutorial and helpfile covers an output between 0 and an upper limit number, but what if I wanted to output any number with a minimum higher than 0, between 100 and 500 for example?

#44668
Jul 8, 2009 at 5:27pm

Have it do a random output between 0 and 400, then add 100 to the output.

#160739
Jul 8, 2009 at 5:28pm

You’d use the range as the argument to [random] in this case it is 400. Then you’d create the offset by connecting a [+ 100] after it. Voila, random numbers between 100 and 500. Each object performs a certain task and it is up to you to connect them together to reach your objective. You can also use [expr] to generate random numbers within certain bounds.

lh

#160740
Jul 8, 2009 at 5:31pm

An alternative way is [expr random(100,500)].

_
johan

#160741
Jul 8, 2009 at 5:35pm

Out of curiosity, is one method preferable over the other?

#160742
Jul 8, 2009 at 5:41pm

Using [expr random(100,500)] seems a more elegant way of doing it than adding 100 as an offset, but I don’t suppose it makes a great deal of difference.

Thanks very much everyone, very helpful as always.

#160743
Jul 8, 2009 at 5:48pm
 pmj wrote on Wed, 08 July 2009 10:41 Using [expr random(100,500)] seems a more elegant way of doing it than adding 100 as an offset, but I don’t suppose it makes a great deal of difference.

Thanks very much everyone, very helpful as always.

Yes, but I’ve always heard that simple math objects are preferred over expr objects for efficiency. I’m curious how using [random 400]–>[+ 100] compares to [expr random(100,500)] in efficiency.

#160744
Jul 9, 2009 at 3:41pm

Probably the easiest (and most efficient) way to do what you want is with any of the basic random number generators in the Litter Power Package.

For instance, [lp.titi 100 500] will generate random numbers in the range [100 500]. Inclusive.

One object, no adding, no expr, and no fiddling around with the range not doing what you want.

As ej hints, the most common error with the standard random object is people almost always set the range one unit smaller than they really want.

Lp.titi is available in the Litter Starter Pack (URI below). The Starter Pack is more Max-4 friendly, but will run on Max 5, despite some some cosmetic error messages. The full Litter Pro bundle is more conscientiously Max5-friendly.

#160746

You must be logged in to reply to this topic.