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
take a look at route
and select
.
[urn] --or is it [bag]? can't remember -- one of these will give you random numbers without repetition
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.
If you're new, then I would strongly suggest that you spend a little quality time with the tutorials - in your specific case, Tutorial 21 (Controlling Data Flow) would be particularly helpful.
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.
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:
Or even better, much like jvkr says, use lists and don't random for the last number (not so nice for huge ranges, naturally):
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
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.
?
This should work?
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
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.
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
change [select] to [route]
Here's a simpler way to do what you're attempting, I think, or at least more general:
[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.