I am working through a Pd online textbook and came across this practice problem. Every time I try to copy the patch provided I receive a "Stack Overflow" message. What am I doing wrong?
-
Stack Overflow Question
-
@b4cat This is possibly solvable within one step each time so without iteration. Say we choose a number out of four. In the first step we have four possibilities, so [random 4]. From there on we have only three possibilities, [random 3], and whenever we choose a number equal or higher than the previous, we can just add one.
-
@ingox i think it is solved like that in this thread (including a discussion if it is accurate ):
https://forum.pdpatchrepo.info/topic/10366/newbie-perspective-on-the-random-without-repetitions-exercise -
Having had a look at the lengthy discussion in the thread @Jona linked, i think i should explain the idea more clearly, as my description above was not accurate.
The basis of the idea is thinking in modulo classes, so a little bit like thinking in circles, like we do with the clock.
Say we draw one out of four numbers, so we use [random 4]. After that we can only choose three numbers as the previous one should not repeat. So we use [random 3]. But we don't start at zero. We start at the previous picked number + 1 and add the random number from [random 3] (0, 1 or 2) and take this modulo four.
Examples:
We choose 2. So in the next turn we can have 3, 0 or 1.
We choose 3. So in the next turn we can have 0, 1 or 2.
We choose 1. So in the next turn we can have 2, 3 or 0.
We choose 0. So in the next turn we can have 1, 2 or 3. -
@ingox thanks, i think i understand. and i assume our examples have the same accuracy?
-
@Jona Yes, both examples should be equivalent. I tested my patch and it produces nearly perfectly distributed results. It is basically not a difficult idea, only the discussion in the thread was so much confusing.
-
@Jona Here is a slight modification to your patch: randomwithoutrepetition.pd
-
@ingox thanks. it is not really my patch, just used the conclusion from the thread i posted as an example.
edit: i removed the second random object again, because then it is possible to change the range without repetitions, and included an initSeed: randomwithoutrepetition.pd -
I created a loop between a nbx and a hslider because I thought I could "mirror" each other's values...
Then I've got a bunch of stack overflow messages each time their values were changed...
Then I found this post...Now it's solved, and I can finally sleep!
Thanks!