Algorithm on random generated numbers with guaranteed that all numbers within the range will be selected once

QWERTY

I was having some problem to come out with a solution for a problem, I am currently still in the thought process. So basically the problem is to random generate numbers between 0 to 12, and get the two numbers to perform multiplication within a time frame.

However, the solution provided must guaranteed that the all 169 random generated number pairs must be shown eventually, so cannot just randomly select a number. I was thinking adding a weight to random selected number helps in this case? Or there is better approach for this?

Thanks!

Erwin Bolwidt

What this boils down to: you don't really want the number pairs to be random, because a random value means that your next value does not depend on any previous value. Instead, you want 169 known number pairs to come up, each only once, but you want the order of them to be random.

As if these number pairs were printed in playing cards, and you were shuffling the playing cards.

And Java has a nice method for that: Collections.shuffle acts like a professional dealer who shuffles a deck of playing cards.

You want an approach where you first generate all the playing cards, and then shuffle them. Something like this:

List<Integer[]> l = new ArrayList<>();
for (int x = 0; x <= 12; x++) {
    for (int y = 0; y <= 12; y++) {
        l.add(new Integer[] {x, y});
    }
}
Collections.shuffle(l);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do i generate 2 random numbers, once within the range of 50 and 259, and once within 50 and 159?

Generate random numbers, letters or characters within a range

Generating and storing unique and random numbers within a range

replace NA in a dataframe with random numbers within a range

Generate 'n' unique random numbers within a range

Printing Non Repeating Random Numbers within a range

Generating random numbers within a specified range

Count numbers within range algorithm (C++)

How do I generate a random range of numbers within another range?

Random numbers once a time

Random numbers algorithm

Is the sequence of random numbers generated by rand, in C, guaranteed to always be the same, for the same seed?

Pyspark - how to generate random numbers within a certain range of a column value?

Generate Array of Unique Random Numbers within Inclusive Range

I want to generate random numbers within given range in java

How to generate random Double numbers in Google Sheets within range?

Outputting 20 different random numbers within a range using php

C++ - generate random numbers following normal distribution within range

How to generate a population of random numbers within a certain exponentially increasing range

generate random numbers within a range with a percentage of them a specific value

Generating random numbers which allows some repetition within a given range

Generating random evenly divisible numbers within a specific range in C++?

generate sample of numbers within range random amount of times in chronological order

Algorithm to find indices of two numbers in Series with difference within a specified range

Saving all random numbers generated by the program then reusing them in racket

Random number in Excel between 1 and 10 until all numbers are selected

Random numbers generated show periodicity

Random numbers only initialize once

Make a list of 50 random numbers in the range 1-50, such that adjacent numbers are not within 15 of each other