Unique Random Numbers

Post any examples or modules that you want to share here
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Unique Random Numbers

Post by tulamide »

Sometimes, random numbers just aren't enough. Imagine you shuffle a deck of cards. They will be in a random sequence then, but each card only appears once. That's exactly what this module, "Unique Random Number Generator", does. It randomizes from a pool of numbers and guarantees that each number will only appear once.

I have good use for it, I hope you'll have use for it, too :D

Download it on Flowstone GURU
"There lies the dog buried" (German saying translated literally)
Exo
Posts: 426
Joined: Wed Aug 04, 2010 8:58 pm
Location: UK
Contact:

Re: Unique Random Numbers

Post by Exo »

Thanks, I'm sure I can find a use for it ;)
Flowstone Guru. Blog and download site for Flowstone.
Best VST Plugins. Initial Audio.
User avatar
JB_AU
Posts: 171
Joined: Tue May 21, 2013 11:01 pm

Re: Unique Random Numbers

Post by JB_AU »

It's nice, but, it's not that random, there is always the minimum & maximum & previous chosen random numbers in a random order :?
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

Albert Einstein
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Unique Random Numbers

Post by tulamide »

JB_AU wrote:It's nice, but, it's not that random, there is always the minimum & maximum & previous chosen random numbers in a random order :?

I see your point, but that's what the module is about. Just like card shuffling, they also are defined in their value and then shuffled. That's what this module does, too.

So, when giving a range of 20 to 29 with a count of 10 values, you will always get a sequence 20 to 29 but in random order. If you want other values, change min, max and/or count.

Is there any special case, you are thinking about? Because a series of totally random values that guarantees no double values is only achievable with tracking everything that was already spit out. That would be a huge list after some time, taking away a lot of RAM and continously increasing the time needed to check, if the next value was already spit out.

You could give me a scenario and I'll see if it is doable.
"There lies the dog buried" (German saying translated literally)
User avatar
JB_AU
Posts: 171
Joined: Tue May 21, 2013 11:01 pm

Re: Unique Random Numbers

Post by JB_AU »

capture.png
capture.png (6.42 KiB) Viewed 27954 times
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

Albert Einstein
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Unique Random Numbers

Post by tulamide »

I confess, I don't understand what you're after. The above can be done with each number only appearing once like this:
randy.png
randy.png (27.37 KiB) Viewed 27949 times
"There lies the dog buried" (German saying translated literally)
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: Unique Random Numbers

Post by tester »

Maybe this will clarify some available options.

Case 1: random randomness. Each next number is randomized from a pool (min/max range). Numbers can repeat in a series.

Case 2: unique randomness. Each next number is randomized from a pool, and then excluded from the pool. Numbers never repeat. With finite pool - it's a lottery game. With infinite pool - numbers are just always unique.

Case 3 a/b/c/d: partial randomness. Either certain ranges of the pool can be emphasized (random numbers are taken from there more often - in a regular or random way), or specific numbers are emphasized to be picked up (randomly or m-times per n-hits). Can be used to create a sort of feedback or quasirandomness.

Case 4: source dependent randomness. A sort of input is added, to influence the randomness (soundcard input for example).
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Unique Random Numbers

Post by tulamide »

tester wrote:Maybe this will clarify some available options.

Case 1: random randomness. Each next number is randomized from a pool (min/max range). Numbers can repeat in a series.

Case 2: unique randomness. Each next number is randomized from a pool, and then excluded from the pool. Numbers never repeat. With finite pool - it's a lottery game. With infinite pool - numbers are just always unique.

Case 3 a/b/c/d: partial randomness. Either certain ranges of the pool can be emphasized (random numbers are taken from there more often - in a regular or random way), or specific numbers are emphasized to be picked up (randomly or m-times per n-hits). Can be used to create a sort of feedback or quasirandomness.

Case 4: source dependent randomness. A sort of input is added, to influence the randomness (soundcard input for example).

Very good summary, tester.

Additionly from me: While Ruby's standard random class offers case 1, my module offers case 2, with case 3 possible through chaining/mixing several instances of my module.
"There lies the dog buried" (German saying translated literally)
adamszabo
Posts: 667
Joined: Sun Jul 11, 2010 7:21 am

Re: Unique Random Numbers

Post by adamszabo »

I think the problem with the schematic is that it seems its not really random. For example when I set the range between 0 and 1 i get 0.1111, 0.2222, 0.3333 and so on. so it seems its dividing by the number you specify. It would be truly random if it writes: 0.1111 then, 0.111253. Its close to 0.111 but still a different value, if you understand what I mean.
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Unique Random Numbers

Post by tulamide »

adamszabo wrote:I think the problem with the schematic is that it seems its not really random. For example when I set the range between 0 and 1 i get 0.1111, 0.2222, 0.3333 and so on. so it seems its dividing by the number you specify. It would be truly random if it writes: 0.1111 then, 0.111253. Its close to 0.111 but still a different value, if you understand what I mean.

I know what you mean, but that's not the intention of this module. In your example, you get 0.1111, 0.2222, etc., because of the count of numbers you entered. Example:
min 1, max 2, count 2 will return either 1 or 2 in random order
min 1, max 2, count 3 will return 1, 1.5 and 2 in random order
min 1, max 2, count 4 will return 1, 1.3333, 1.6666, 2 in random order
min 1, max 2, count 5 will return 1, 1.25, 1.5, 1.75, 2 in random order
and so on

So don't ignore count, it defines the count of numbers you want to get returned. done triggers, when count numbers are returned, so you can then generate a new sequence.

Again, imagine a card deck. It has a fixed number of cards, like 32 or 54 or w/e, those cards then are shuffled so that they appear in random order, with each card of the deck appearing exactly once. count is like defining the size of the deck, min and max are defining the range of numbers that is evenly distributed over the cards, and start is the equivilent of shuffling the cards. request next in this analogy is the dealer giving you a card.

Back to your example: That's the intention of the module. Not the numbers are random (you define them with min, max and count) but the order in which they appear. That's what this module is about.
"There lies the dog buried" (German saying translated literally)
Post Reply