Forums > MaxMSP

Random except for previous number

March 6, 2012 | 9:13 pm

Hi all,

This sounds a bit silly bit after having searched for 3 hours I have given up!
I want random numbers in my patch, so I used random. But I don’t want the same number twice. I want the number to be a different number than the random number generator has already given. (I can’t use the "urn" function here because for instance if it has given number 1 it must give 2 or 3,4,5 etc. and if it has given 5 it must be able to give 1 again as a possible output (but not 5!))

Hope I was clear!
Thanks!

Attachments:
  1. TrainPlay.maxpat


MIB
March 6, 2012 | 9:55 pm

not sure I get it 100%, but did you look at [urn-jb] ?


March 6, 2012 | 10:58 pm

Yes you are right! It did the trick. Thanks!!


March 7, 2012 | 12:14 am

Another approach I had floating around (maybe slightly more random):

– Pasted Max Patch, click to expand. –


ark
March 7, 2012 | 1:33 am

Here’s a general technique that I think does what you want.

Suppose you want a series of random numbers between 1 and n, where each one is different from the last one.

For the first number, just pick one between 1 and n. Remember it.

For each number after the first, pick a number between 1 and n-1. If the number is >= the one you remembered, add 1; otherwise use it unchanged. Replace the remembered number by the new one.

I would think this could be done with no more than a handful of objects.


March 9, 2012 | 7:43 am
– Pasted Max Patch, click to expand. –

March 9, 2012 | 10:26 am

1. compare every output with the previous one using [==]
2. if repetition is "true", just trigger the random generator again.


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