• ### Beginner - Randomizing Number Order

I want to make a patch with four number boxes, which feed into various other parts of my patch. For each part of the patch I would like those four numbers to be in a random order.

e.g.

Numbers are: 3,4,6,7

... so they could then be:

4,6,7,3
4,3,6,7
7,4,6,3

etc.

I'm sure this is not too complicated, I'm not not sure the object to use. I should also make clear that there would be number boxes being used, so the patch is dynamic and realtime.

Many thanks for any help

• Posts 16 | Views 6667
• you could write the values to a table and read them out with [shuffle]. probably there are other solutions - maybe with [list-idx] or something. i attached a patch that uses the table approach - i didn't test it much, but seems to work.

http://www.pdpatchrepo.info/hurleur/randomize.pd

• Thanks for the code. I'm quite new to PD some it's taking me a bit of time to see exactly what is going on.

However a quick look at the results shows me it's not truly random, there are many patterns that are disproportionately repeated, and some which do not occur at all.

Thank you very much for taking the time out to help me It's very useful for me to look at such code to understand my problem better.

I will keep looking into it - and if there are any more ideas/thoughts I would be highly grateful.

• there should be 16 possibilities:

1 2 3 4
1 3 2 4
1 4 2 3
1 4 3 2

2 1 3 4
2 3 1 4
2 4 1 3
2 4 3 1

etc.

unless you want to expand to 10 or more numbers, then you probably don't have to follow an algorithmic approach.

so, this would be simple:

[random 16]
|
[sel 0 1 2 3 4 5 .... ... 15]
| | |
[1 2 3 4( [1 3 2 4( [1 4 2 3(

etc

• oops, been a long time since i did combinations/permutations in school. i undercalculated the number of messages you'd need.

anyway, here is what u want, with an algorithmic method based on something i found in the rtc library. the good thing about this one is it's easily exandable if you need 5 or 6 or more number boxes too. just add more number boxes in, and then in the couple of places in the patch where you see a '4', just change that to a 5 or 6.

http://www.pdpatchrepo.info/hurleur/randomGen.pd

• Another option would be to fill a table with the values and use [urn] to come up with the table indices. [urn] is like [random], except it doesn't repeat values.

• ahh, urn was what i've been searching for - i looked up [shuffle] in the list of objects at flossmanuals. thanks..

• there's a vanilla version of urn hidden in the subpatch of the example i posted. i'm glad someone else patched it up though, cos it's not as simple as you might think.

• I've spent the last few days trying to make sense of all this. I thought it would be much easier.

Mod, thanks so much for the patch. I'm trying to make sense of it. I understand what it is doing, but I want to understand how. Although it works, just as how I would like it, I don't feel comfortable using code I don't understand.

Maelstorm thanks for the suggestion, from what I can understand that is what the randomGen patch is doing. I understand your suggestion, although I still can't quite work out how to make it.

I will crack on with this though, it's all very interesting

• Yeah i didn't make the subpatch.

While i could go through it and figure out what it all does, i'm actually quite happy to just accept that it works how it should. As long as it's vanilla pd, there's nothing hidden from me, so if i really need to find out what's happening i can.

But at the moment, i've never had any need to go that far with that particular one.

• Yeah, thanks. Perhaps you are right. It seems well and truly above my head. It's probably best just to use it for the moment, and work it out in the future when my understanding is more advanced.

Thanks for putting me on to it

• it's not that hard to explain, but it's just a lot of work to go through it all, for probably very little gain.

you'd be better off investing your efforts elsewhere in making other things work (unless you specifically want to focus on being a random number generation guru)

• Not to take anything away from the other suggestions, but this is what I was thinking with [urn].

http://www.pdpatchrepo.info/hurleur/randomize-urn.pd

• yeah, that is nice and elegant, much better than my dynamic messaging approach.

here's the same thing with a vanilla urn

http://www.pdpatchrepo.info/hurleur/randomize-urn-vanilla.pd

• and the vanilla urn abstraction:

http://www.pdpatchrepo.info/hurleur/diy-urn.pd

• ..-.and another way to make [urn] based on the post from mrpeach in this recent thread on the pd-list:

http://lists.puredata.info/pipermail/pd-list/2010-10/083396.html

http://www.pdpatchrepo.info/hurleur/slp_urn.pd

Posts 16 | Views 6667
Internal error.

Oops! Looks like something went wrong!