# Random sorting not random?

Ok this is extremely weird. I have a quiz app, and this particular quiz has a bank of 62 questions. It’s supposedly randomly sorting them, then choosing 10 for the quiz. But every single time, the “random” questions get paired up perfectly for at least 8 of the questions. Just try it:

It’s always the same order too, with the True question coming before the False question. The way it’s organized in the database, I made 2 sets of questions. #1-#31 are all the true questions, and #32-#62 are all the false ones, with each of the pairs exactly 31 apart (e.g. “thus”=true is #17 and “thus”=false is #48).

I’ve made lots of quizzes so far, but only this one seems to produce this non-random pattern, so my guess is that the number 31 is important in the programming? Anybody know what’s happening here?

Isn’t it better to just add a data type like “true? → yes/no” to know if it’s true or not?
Maybe the problem is in relying the item number to know if it’s true or not…
Idk, the amount of info doesn’t give much to work with
to give a better answer we would need how the search is done (data source) and how the data base is built

1 Like

Sorry, I wasn’t clear. Here’s how my RG is searching:

There are 62 things that it’s supposed to sort after this search, but it always pairs up items that are 31 things apart in the database. I can tell because each thing has a unique question number from 1-62. So my list ends up looking like some version of this every time: 10, 41, 22, 53, 3, 34… etc. (Notice that 10+31=41; 22+31=53; and 3+31+34.) And since 10 & 41 are similar versions of the same question, the “randomness” always has these obviously non-random pairs in the quizzes that I’m generating. It’s really weird.

I can probably solve it by just reordering my questions so #32-62 aren’t perfectly symmetrical to #1-31, but it would likely still mean that certain pairs of questions are always together, which isn’t really random. I’d love to understand better how random sorting works so that I don’t encounter this issue again. A lot of my site is dependent on randomization.

cool, maybe that 31 is important after all, I wouldn’t know how it either haha

I did some experimenting with my other quizzes, and the same thing happens. Pairs of questions always appear together in the same order. The numbering is slightly different (11 things away in the database), but the pattern is unmistakable. No matter how many times I refresh the page or what browser I use, the random sorting always pairs up the same things from the database. The order of the pairs will be different, but the pairs are always stuck together. This is very obviously not random!

After more digging, it’s not just pairs of questions that go together. The entire list is always in the same order, but the starting question changes. Here’s the order of one refresh for a list of 20 things:

At first glance, the question numbers appear to be in a random order, but the second column shows that there’s clearly a pattern of some kind since the difference between consecutive question numbers is always 9 or 11.

Refreshing the page, the starting question # will change, but the order is always the same. So a refresh might have question #10 as the first item, but the order will always follow what’s listed in the chart: 10, 19, 8, 17, 6, 15, etc… The list wraps around back to the top (12) when it gets to the bottom (3).

Again, here’s the code that I’m using:

Why isn’t the random sorting anywhere close to random???

To build a random list of questions, try an operation like this “pull from a hat”.

Then after each item is “pulled from the hat” at random, add it to a list and display that list.