Random except for previous number

Mar 6, 2012 at 9:13pm

Random except for previous number

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
#62174
Mar 6, 2012 at 9:55pm

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

#224563
Mar 6, 2012 at 10:58pm

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

#224564
Mar 7, 2012 at 12:14am

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

– Pasted Max Patch, click to expand. –
#224565
Mar 7, 2012 at 1:33am

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.

#224566
Mar 9, 2012 at 7:43am
– Pasted Max Patch, click to expand. –
#224567
Mar 9, 2012 at 10:26am

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

#224568

You must be logged in to reply to this topic.