randome no duplicates.

mirage's icon

hi there everyone. i need to create a random object that puts out 10 integers between 1 and 26 without repeating any.

basically right now i have a bang into an {uzi 10} then into a {random 25} then into a {+ 1} then into {zl.group 10} then to a {message}

this eliminates 0 and puts out numbers between 1 and 26

HOWEVER!

there are repeats in the numbers which makes this useless for what i need it for.
can anyone help me get a string of 10 RANDOM numbers without any repeats?

many thanks in advance

MiRAGE

bkshepard's icon

If you look at the help file for [random], there is a list of "See Also" objects. I find this list to be incredibly useful when I'm looking for a particular function, but can't think of the name of an object. Check out the object [urn], it does what you want.

mirage's icon

im not sure urn will do what i want.

----------------DESCRIPTION------------------------------
urn

Generate random numbers without duplicates

outputs random numbers and keeps track of each number that has been generated
When all numbers up to the maximum (set via an argument or the right inlet)
have been output, a bang is sent out the right outlet.

---------------------------------------------------------

it seems like it sort of counts up to the maximum by randomly outputting values ore something. i have tried various combinations of this and i just cant see how it will work.
can someone explain how i would go about this with "urn" ? or if not how else i can reach my goal?

many thanks

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

Send clear to urn after you generate your 10 unique integers.

leafcutter's icon

you would just replace 'random 25' with 'urn 25' and you could use the uzi finished bang to send a clear message to urn so you don't run out of numbers - once urn has output all the numbers in the range you select it stops outputting until you send 'clear'. Maybe this is what is confusing to you?

Aaron Wharton's icon

Sorry for reviving, but I'm running into an issue:

The lower the range, the higher the probability that urn will choose the same value that triggered the clear message. Is there a way around this?

Source Audio's icon

bang if repeated

Aaron Wharton's icon

Still not entirely sure what I'm doing wrong. =/
(only choosing 2 as the range for ease of checking)


Regardless, I very much appreciate the effort.

Source Audio's icon

adding a littel delay might help

Max Patch
Copy patch and select New From Clipboard in Max.

Roman Thilenius's icon

just as a note, there is nothing like "the most random next message" anyway.

so if you try to avoid having "7, 7" by filtering out repetitions you will only produce the possible occurance of "7, n, 7" with about the same chance.

Bill 2's icon

I'm not sure exactly what problem you're having, Aaron, but just in case it helps here's part of an abstraction of mine that avoids repetitions for random and urn:

Max Patch
Copy patch and select New From Clipboard in Max.

It's old, so there are probably better ways to do it, and by glancing at it I'm not even sure how it works. :-) But it does.

Tj Shredder's icon

If you look at it like the 6 out of 49 lotto or something like that, then fill a bag and grab one out of it, remix and grab the next:

Max Patch
Copy patch and select New From Clipboard in Max.

Basically its urn with zl...;-)

Aaron Wharton's icon

Re: everyone who has responded since —
bows. down. low.

Seriously, thanks so much. <3