Forums > MaxMSP

Setting a non-zero floor for Random or Drunk

July 30, 2008 | 2:56 pm

Hi all,

I’m happy to say that this is my first post to these forums, but I’m not entirely sure if this question is what they’re supposed to be used for (getting help in understanding how to use a max object). I’d just like to say how pleased I am to return to Max after using it in college. Max 5, for me, has been very fun to use–and I was floored when I saw the improvements that have been made in GUI alone, let alone everything else, (which I’m sure is more important).

My question is sort of a how-to in nature. Essentially, from what I understand about random and drunk, each of them begin their processes from 0. From reading the help documentation about the objects, I am unable to discern whether or not it is possible to change this. Suppose I want to generate a random number between 5 and 20?

Is this possible, and how might I think about doing it? Any advice is most-appreciated. (I’m sure it’s likely very easy, and I may just be missing something very simple!)

Thanks very much for reading,

Steve


July 30, 2008 | 3:29 pm

Welcome.

[expr random(x,y)] zhere x is the minimum and y is the maximum. A bang will trigger a random number.


July 30, 2008 | 3:31 pm

And of course you could just put [+ x] after your drunk/random object and adjust the maximum accordingly.


July 30, 2008 | 3:45 pm

Thank you for this information!

What you are indicating is that there is no way to set the floor of a random object itself with, say, an argument passed to it, is that correct?


July 30, 2008 | 4:03 pm

Not that I know of. There’s nothing in the documentation either but:

[random 64]
|
[+ 64]

will do the same thing as

[expr random(64,128]

The only difference between [drunk] and [random] is that the drunk is based on brownian motion (http://en.wikipedia.org/wiki/Brownian_Motion) and allows the step size to be adjusted so unless you need the Brownian motion, just use expr.



kjg
July 30, 2008 | 4:23 pm

welcome to the forums!

generally, you should get familiar with the concept of offsetting and scaling. you have to regularly scale/offset the output of objects when working with max. there are a few objects to help you with these tasks, but it is probably smart to learn how to do it "the hard way" first.

say you want a random range of 10000 steps between 1 and 2?

[random 10001] (gives you a range of 10001 values: 0-10000)
|
[* 0.0001] (scales the values to the range 0-1)
|
[+ 1.] (offsets the range by 1: 1-2)

voila. this also works the massage the output of signal rate objects. just use *~ and +~ instead.

regards,
kjg


July 30, 2008 | 4:33 pm

gary nelson’s random objects allow a variable floor

http://www.timara.oberlin.edu/~gnelson/maxdownloads/downloadmax.htm


July 30, 2008 | 4:57 pm

On Jul 30, 2008, at 7:56 AM, Steven Kukla wrote:

> Is this possible, and how might I think about doing it?

I would encourage you to think about it from two perspectives:
– what is the math involved?
– how do I encapsulate this in a useful way?

Here’s an abstraction, which I call RandomRange, which takes two
arguments, RangeLow and RangeHigh. It generates random values between
those two numbers. It also has inlets for the high and low value.

– Pasted Max Patch, click to expand. –

Chris Muir
cbm@well.com

http://www.xfade.com


July 30, 2008 | 9:54 pm

Thanks to all of you for your wonderful suggestions and for taking the time to help guide me. I’ll be experimenting with all of the methods presented, from doing it the hard way to Gary Nelson’s random objects, to Mr. Muir’s abstraction.

One question I have is, first, about the abstraction. Here’s what was generously provided:

– Pasted Max Patch, click to expand. –

Now, I’ve never seen this before. On a hunch, I looked up ‘abstraction’ in the Max 5 Help window and got some useful information about sub-patchers, which I remember from school, but I’m not sure how to translate the above material into something usable in Max. Could someone offer some advice for this, or point me somewhere to read so I don’t take up people’s time with simple things?

Regarding the "hard way" examples, am I correct in assuming that the reason these act the way they do is because the random object sends a number out which can then be manipulated in any way provided by the programming language? (IE, you can add to the number, subtract from it, etc?

If this is the case, then, is it logical to assume that if I do something like:

[random 5]
|
[+ 1]

any number which comes out of random is simply increased by one? This explains the increased floor from 0 to 1, but would it not also increase the given argument 5 so that the random’s range of numbers is actually 1 – 6?

I apologize if these are somewhat banal or pointless questions, but I’m eager to learn…

Thanks so much to everyone for their willingness to help!

Steve


July 30, 2008 | 11:05 pm

The easiest way to do what you want is [lp.titi 64 128]

Lp.titi is part of the Litter Starter Pack, which is available at the URI below.

Yes, you can also do the following:

Quote: Steve_K wrote on Wed, 30 July 2008 23:54
—————————————————-
> [random 5]
> |
> [+ 1]
>
> any number which comes out of random is simply increased by one? This explains the increased floor from 0 to 1, but would it not also increase the given argument 5 so that the random’s range of numbers is actually 1 – 6?
—————————————————-

Your thinking is *almost* right, but you’re making the same mistake fairesigneaumachiniste made. [random 5] gives you random numers in the range zero to *f*o*u*r* (as in five distinct values: 0, 1, 2, 3, 4. Count’ em). Adding one offsets the range to [1 .. 5].

Adding an offset may not seem to be hard to do, but it’s amazing how often people manage to get it wrong.

Which is why Litter Power is the easier way. It also has a more robust random number generator at its core.

If you’re serious about randomness, you really owe it to yourself to look at Litter Power.

Best,
Peter


July 30, 2008 | 11:11 pm

On Jul 30, 2008, at 2:54 PM, Steven Kukla wrote:
> I’m not sure how to translate the above material into something
> usable in Max

Select all the "funny text" including the begin / end lines, copy it,
go to Max, select New From Clipboard from the File menu, and you now
have a patcher.

Save this somewhere in your search paths, and you can use it just like
any other Max object.

-C

Chris Muir
cbm@well.com

http://www.xfade.com


July 31, 2008 | 2:17 am

Thanks to both Peter and Chris for your suggestions.

I’ll be trying both methods. Chris, again, I apologize for not quite getting something. Your patcher looks great, and I understand how to use it, so that’s not the problem. However, I’ve done some searches on search paths, and I’m not quite sure how to save this object so that I can use it and then have it autocomplete when I type in its name in an object box.

Following the help file provided for search paths leads me to find two folders, ‘patches’ and ‘examples’ inside my Max5 folder within the Applications folder. I figured since I want to save it as an object, I’d keep it within the object-prototypes folder and then create my own folder ‘randomrange’ within it and save the file as a .maxproto just like the others. Somehow I knew this couldn’t be correct, but I’m unsure how to a.) find where the Max objects are stored on my system so I can add this one to them or b.) how best to think about using a search path.

If the concept of adding a custom object to a collection of ‘stock’ program-included ones is incorrect, what is the best way to incorporate custom objects into max? Perhaps just create a folder called Custom Max Patches and add it to the search path, I suppose? Although I had hoped to add it to the stock collection somehow, as this seems to me to be a more organized solution.

Anyhow, thank you both for your help, and I look forward to continuing to learn!

Steve


July 31, 2008 | 3:00 am

On Jul 30, 2008, at 7:17 PM, Steven Kukla wrote:
> Perhaps just create a folder called Custom Max Patches and add it to
> the search path, I suppose?

That would certainly work, but the way I approach it is to have one
top level folder that I set a search path to, let’s call it
MyMaxStuff. I’m on a Mac, so a logical place to put this is in the
Documents folder inside my home directory.

When you set the search path to your MyMaxStuff folder using Max’s
File Preferences dialog (Options menu), make sure that the Subfolders
box is checked. I keep all my projects in this folder, as well as a
couple folders for my abstractions that get used across projects, and
3rd party stuff.

The first time you instantiate an abstraction you’ll have to type the
whole name, but from then on out, it will be in the auto-complete list.

-C

Chris Muir
cbm@well.com

http://www.xfade.com


July 31, 2008 | 4:41 am

Thanks for that info, Chris, it helps a ton.

The next question I have is more of a conceptual how-to than an object one. Part of me would like to ask for different ways to achieve what I’m after, while another (admittedly smaller) part would simply like some advice as to how to THINK about this idea using Max, seeing as I’d like to be able to get good enough with Max so as to be able to figure things out on my own. That said, here’s the idea:

When working with samples, if I have a string of notes with the same velocity, these notes sound horribly un-realistic and take on the dreaded machine-gun effect. Usually, the higher-end libraries have multiple layers of samples triggered by velocity, so that, for example

1 – 25 = pp,
26 – 51 = p,
52 – 77 = mf,
78 – 103 = f,
104 – 127 = ff

My idea is to write a patch which will take a given set of notes and, while active, generate phrases with randomly generated velocities which hover, but do not stray from an initial velocity.

So, if I give the patch an initial velocity of 15, say.

The patch would first understand that the number is within the first velocity range of 1 – 25. Therefore, it must use 1 as a floor and 25 as a ceiling for any resultant velocity it returns.

I could then set a differential of 3, and then generate a passage which could have random velocities of anywhere from 12 – 18 (that is, +3 or -3 from 15)

So, it would stay within a given large area, but then generate a defined +/- curve within that area.

That’s the first part of this idea. There are some issues and problems that I think might halt this idea in its tracks, which I’ll likely pen out later… Namely the fact that it might be hard to play something in real time with this patch. Example, what if I want to stop the behavior and play a crescendo? I imagine there might be a way to trigger the patch to turn "on" by using some sort of unassigned midi controller from within a sequencer…

Anyhow, HOPEFULLY, the overall idea is clear…

Any ideas on how to begin thinking about such a project would be much-appreciated. I’ve already figured that with Mr. Muir’s RandomRange object, I can set my larger random ranges. Perhaps somehow combining the functionality of RandomRange with Drunk would give me defined random ranges and the ability to define a step size of + or – an int?

Just trying to think things through. Thanks for reading!

Steve



kjg
July 31, 2008 | 12:23 pm

Quote: Steve_K wrote on Wed, 30 July 2008 23:54
—————————————————-

> [random 5]
> |
> [+ 1]
>
> any number which comes out of random is simply increased by one? This explains the increased floor from 0 to 1, but would it not also increase the given argument 5 so that the random’s range of numbers is actually 1 – 6?

yes, the floor is offset by 1.

[random 5] produces a range of 5 random values, namely 0-4.

you then offset this range by 1, resulting in the range 1-5.


July 31, 2008 | 5:35 pm

On Jul 30, 2008, at 9:41 PM, Steven Kukla wrote:
> Any ideas on how to begin thinking about such a project would be
> much-appreciated.

It seems like you’re thinking about your problem fairly clearly and
that your goals are also pretty clear. I think it’s time to roll up
your sleeves and start coding to see if you still think your goals are
interesting at the end of the day.

An ounce of experimentation is worth a pound of discussion (and you’ll
probably get more ideas along the way.)

-C

Chris Muir
cbm@well.com

http://www.xfade.com


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