• ### Random number without repetition

Hello to all,

I am currently studying from loadbang book, and while only in the beginning at it, there's this exercise:

You have to make a patch where a random object doesn't generate same number twice. I made something, but got into an issue using trigger. While without it the patch seem to work in a very primitive way, with the trigger it does not and I cannot understand why.

Could someone help me?

Random no repeat (trigger issues).pd

• Posts 11 | Views 6745
• @jazzsnob Hello there......
In the left hand scheme you are sending a float (number) from [random 4] to both the next objects.
So with your trigger you need to use [t f f] and not [t f b] so that the float is sent out of both outlets in the correct order.
[t f b] sends a "bang" from the "b" and passes the float to the "f".

The three schemes will still not send the same values, because [random] actually sends a series with even value distribution...... so always the same series of numbers......... except....... when you create more [random] objects the series is shifted for each one by a random amount.
Hope that helps.....
David.

• @whale-av thank you so much - in the end it was pretty simple hehe

However, if you have a spare moment and could explain me this: why did BANG not work and I had to use 2 f in my trigger object?

• @jazzsnob Here you go...... I hope it makes sense....... trigger_why.pd
and here is some work I did a while ago trying to get more "randomness". These patches will not prevent 2 sequential numbers being the same though..... as that would not be "random".......
true random.zip
David.

• Jumping in this thread just to clarify something. When you say that a random number generator shouldn't repeat the same number twice, do you mean it shouldn't do this twice in a row, or it shouldn't repeat a number before it spits all the numbers in its range? The second behavior is like cyclone's [urn] if I'm not mistaken and it's not very easy to achieve. I've tried in the past, and this thread motivated me to work on it more, and finally made it. I've uploaded it on my miscellaneous_abstractions GitHub repository. It's called [vanillaUrn].

• @alexandros The idea is to print out numbers without repetition. Your idea is so much more advanced that I am not even going into that yet hehe

@whale-av Thank you so much - you have no idea how helpful it is. I understand that [b] is so much more different as it doesn't send any number, while [f] does, correct? I mean that was the whole problem with my little patch.
Yet, I am uploading other modifications, which I do want to understand - maybe you'll be interested, too? 1 working - 2 not working.pd It basically is the same patch with 3 different versions, which I cannot understand why the 1st is working and other 2 do not.

I am asking this (and annoying everyone in the forum with this stupid questions) because as I do not understand it, I am afraid to proceed further with studying. Or perhaps I am too paranoid and should just let it be and what I know is sufficient enough?

• There's different kinds of random number generation. It makes sense for you to to think about what you really need.

This is because

• true random repeats numbers whenever it wants to. Computer random is always the result of a calculation, therefore not really random, but it does create repetitions whenever it wants to as well:
This is, what the random object does.

Then as well

• musical random tends to not wish for (direct) repetition within a certain range of numbers.
If it is enough to not get the same number twice after another, then you can store the last number in a float to compare it to the next one, and if it is the same, then just re-bang the random object.
If you need non-repetition within say 6 numbers, then use urn.

If you use Vanilla you have no urn, so you will have to go differently:
Example
Fill an array with numbers 0-9 on array positions 0-9.
Use the result of random 10 (say 7) to remove the respective position (so 7) from the array. This number (7) is the first of your non repeating random sequence using numbers from 0-9.
Your array will now have only 9 entries.
Repeat the procedure with random 9.
Your array will now have only 8 entries.
Repeat the procedure with random 8.
[…]
When your array has only one value left you read that one out, delete it and refill the array with 0-9 to restart the procedure.

You can do this with as many value as an array fits and you’ll never have any repetition until every number in the range has been used.

Hope that helps.

aircushionfinish.com &#8226; kliklak.net &#8226;

• @jayrope thanks for such detailed reply. Yet, what I needed (to do an exercise from the book 'Loadbang'), is done. Now I want to understand why certain patches I wrote worked, while others didn't.

You mentioned there are two kind's of pure data programs - vanilla and extended? correct? Which one to use for beginner? THANK YOU!

• @jazzsnob Hello again.....
I have tried to explain why your patch works. I will look at the non-working one if you really need me to, but I think you will be able to see for yourself.......
Everything has to do with the "order of operations" in Pure Data...... you should read this.........
http://puredata.info/docs/manuals/pd/x2.htm
Here is your working patch explained (I hope!) for [random 2] and also for higher values......
but the link above will help you a lot. Don't give up..... it's good stuff!

I suggest you start a new thread for any other problems you have, as you are attracting posts that will interest you or be understandable only after a few months of patching......
The word RANDOM is like a magnet to many of us!

Come back here again later though..... a lot of great stuff will have been added to your thread.
David.
part1.pd

• @jazzsnob If want to learn the intestines: Vanilla. Otherwise pd-l2Ork. Extended is NOT maintained anymore. Though it might work See http://puredata.info/ for reliable info.

aircushionfinish.com &#8226; kliklak.net &#8226;

• @whale-av Underdstood - thank you!

@jayrope - I was using extended. Switched to vanilla Thank you, too!

Posts 11 | Views 6745
Internal error.

Oops! Looks like something went wrong!