Random except for previous number

Rene's icon

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!

3495.TrainPlay.maxpat
Max Patch
MIB's icon

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

Rene's icon

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

Ben Bracken's icon
Max Patch
Copy patch and select New From Clipboard in Max.

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

ark's icon

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.

Christopher Dobrian's icon
Max Patch
Copy patch and select New From Clipboard in Max.
Roman Thilenius's icon

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