Page 1 of 2

Unique Random Numbers

Posted: Thu Nov 27, 2014 7:29 pm
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

Re: Unique Random Numbers

Posted: Thu Nov 27, 2014 10:25 pm
by Exo
Thanks, I'm sure I can find a use for it ;)

Re: Unique Random Numbers

Posted: Fri Nov 28, 2014 10:50 am
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 :?

Re: Unique Random Numbers

Posted: Fri Nov 28, 2014 11:02 am
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.

Re: Unique Random Numbers

Posted: Fri Nov 28, 2014 12:27 pm
by JB_AU
capture.png
capture.png (6.42 KiB) Viewed 27958 times

Re: Unique Random Numbers

Posted: Fri Nov 28, 2014 2:26 pm
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 27953 times

Re: Unique Random Numbers

Posted: Fri Nov 28, 2014 2:50 pm
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).

Re: Unique Random Numbers

Posted: Fri Nov 28, 2014 4:02 pm
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.

Re: Unique Random Numbers

Posted: Sat Nov 29, 2014 3:11 pm
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.

Re: Unique Random Numbers

Posted: Sat Nov 29, 2014 5:22 pm
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.