New at Max: Filtering Numbers and Avoiding repetition

    Mar 31 2010 | 4:37 am
    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.

    • Mar 31 2010 | 5:22 am
      take a look at route and select.
    • Mar 31 2010 | 5:52 am
      [urn] --or is it [bag]? can't remember -- one of these will give you random numbers without repetition
    • Mar 31 2010 | 6:55 am
      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.
    • Mar 31 2010 | 6:57 am
      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.
    • Mar 31 2010 | 8:51 am
      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.
    • Mar 31 2010 | 9:29 am
      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):
    • Mar 31 2010 | 9:56 am
      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.
    • Mar 31 2010 | 10:03 am
      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.
    • Mar 31 2010 | 10:11 am
      This should work?
    • Mar 31 2010 | 11:56 am
      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
    • Mar 31 2010 | 12:29 pm
      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.
    • Mar 31 2010 | 1:33 pm
      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.
    • Mar 31 2010 | 4:05 pm
      change [select] to [route]
    • Mar 31 2010 | 6:57 pm
      Here's a simpler way to do what you're attempting, I think, or at least more general:
    • Mar 31 2010 | 7:39 pm
      [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.