## New at Max: Filtering Numbers and Avoiding repetition

Mar 31, 2010 at 4:37am

# New at Max: Filtering Numbers and Avoiding repetition

Hey there guys. Im new to Max as you all have been in the past, and I have come to these forums as a last resort as the help guide has not helped me in this matter.

I am producing a stream of random integers in a range of 24, but some of these numbers I want to avoid. For example, I don’t want the numbers 5, 7, 13 and 20 to be produced. I am just wondering how I go about excluding these numbers (I already know how to produce random values in a particular range).

I also am trying to work out how to avoid repetition in this stream of numbers, or in simpler terms, I want to avoid having two of the same numbers in a row. For example, I dont want the stream to print 3, 18, 14, 8, 8, 20.

If anyone could give me any information about how I go about doing this, it would be greatly appreciated as I am new to Max and want to learn it as quickly and efficiently as possible.

Cheers

#49441
Mar 31, 2010 at 5:22am

take a look at `route` and `select`.

#177605
Mar 31, 2010 at 5:52am

[urn] –or is it [bag]? can’t remember — one of these will give you random numbers without repetition

#177606
Mar 31, 2010 at 6:55am

Well, urn gives you random numbers without repetitions, but it’s too restrictive for the case here. Urn will never output a number again until all other numbers in the set have been put out. But what stuart.richards was asking, was merely to stop numbers from being put out twice in a row. A simple [change] object should do the trick here. (Alongside the mentioned route/select to filter out numbers – or an if, if you prefer.)

P.S. If you use route/select/whatever to filter out a number, but STILL want to get a new random number on every bang, you’ll have to use the “if input doesn’t match” output of route/select to trigger a new bang to the [random] object.

#177607
Mar 31, 2010 at 8:51am

Step 1: fill a list with the numbers you want (zl reg / zl group)
Step 2: slice off a portion (zl slice)
Step 3: take randomly a number from this portion (random, zl mth)
Step 4: join the two slices and the number together (zl join) and make this the input for the next step

The size of what is sliced off in step 2 controls the amount of steps it takes before a chosen number appears a second time.

#177609
Mar 31, 2010 at 9:29am

If it’s ok to not have a print or trigger every single time you bang the random, I’d go for:

[random 21] -> [change] -> [route 5 7 13 20] -> right outlet

If you do need a new number every tick with the same method, maybe:

– Pasted Max Patch, click to expand. –

Or even better, much like jvkr says, use lists and don’t random for the last number (not so nice for huge ranges, naturally):

– Pasted Max Patch, click to expand. –
#177610
Mar 31, 2010 at 9:56am

I have taken all your advice and tried to work it out and am nearly there. The only problem is when a note should be repeated, instead of being repeated it just comes up with silence, i.e. converts the repeated number into a note off. Instead of a note off, I want another note to be played which is not a repeated note.

Attached is the current setup that i have in the maxpat. If you guys could continue to help me out I would be really greatful.

Also if you have any tips or techniques on how to clean up the whole interconnected numbers bit in the middle, that would also be greatly appreciated.

Cheers

[attachment=128611,310]

###### Attachments:
#177611
Mar 31, 2010 at 10:03am

Create a coll with contents:
1, 1;
2, 2;
3, 3;
4, 4;
5, 6;
etc. (miss out the numbers you don’t want)
Then create an [urn 21] object and connect the output to the coll. The urn can be triggered using metro.

?

#177612
Mar 31, 2010 at 10:11am
– Pasted Max Patch, click to expand. –

This should work?

#177613
Mar 31, 2010 at 11:56am

freeman999, this is similar in the outcome to the patch that I uploaded a photo of. When a note is repeated, it leaves a pause, and i want to try to get around that

#177614
Mar 31, 2010 at 12:29pm

In your first post you mentioned you wanted to filter out repetitions? Now you do want them?

Anyway, I think you now know all the objects you need for this, so I don’t think a solution is too difficult, particularly the one to your last question.

#177615
Mar 31, 2010 at 1:33pm

Ive worked everything out guys and it all seems to be good and in working condition. The only thing i ask, if you have time, is to find a solution to the clutter of numbers.

If you could help me with that, it would be great. If not, thanks for all your help.

Cheers

#177616
Mar 31, 2010 at 4:05pm

change [select] to [route]

#177617
Mar 31, 2010 at 6:57pm

Here’s a simpler way to do what you’re attempting, I think, or at least more general:

– Pasted Max Patch, click to expand. –
#177618
Mar 31, 2010 at 7:39pm

[urn] for a linear or linear-based range, and [coll], like somebody already
suggested for the other task with the group to be compared to.

#177619

You must be logged in to reply to this topic.