Are prime numbers really random?
While practicing to code for my college course I stumbled upon this and would like to know if this is something new or significant as I haven't found anything resembling it on the internet.
Let $p_i$ be $i$-th prime number and $n$ some fixed natural number. Let also
$$ s= p_1p_2\dots p_n$$ $$ q_i = s/p_i, i=1\dots n$$
Now we look at all possible residues of certain form, specifically:
$$ S = \{q_1r_1+...+q_nr_n \bmod s, r_i \in \{1, ..., p_i-1\} \}$$
Now let $x_2 \in S$ be the second-smallest in the set. The claim now is:
Let $q\in S$ such that $q<x_2^2$. Then $q$ is a prime and $q > p_n$.
For example:
$ p_1, p_2, ..., p_n = 2, 3, 5 \\$
$ q_1 = 3\cdot5 = 15 \\ q_2 = 2\cdot5 = 10 \\ q_3 = 2\cdot3 = 6 \\$
$ r_1 \in \{1\} \\ r_2 \in \{1, 2\} \\ r_3 \in \{1, 2, 3, 4\} \\$
$ s = 2\cdot3\cdot5=30 \\$
$ x_2 \equiv 7 \equiv 15\cdot1 +10\cdot1 +6\cdot2 \:\text{mod}\: 30 \\ 7^2 = 49 \\$
The full sequence of primes is clearly not random.
$ 0 \\ \color{blue}{1 \equiv 31 \equiv 15\cdot1 +10\cdot1 +6\cdot1 \:\text{mod}\: 30} \\ 1 \\ 2 \\ 3 \\ 4 \\ \color{red}{5} \\$
$ 6 \\ \color{blue}{7 \equiv 37 \equiv 15\cdot1 +10\cdot1 +6\cdot2 \:\text{mod}\: 30} \\ 8 \\ 9 \\ 10 \\ \color{red}{11 \equiv 41 \equiv 15\cdot1 +10\cdot2 +6\cdot1 \:\text{mod}\: 30} \\$
$ 12 \\ \color{blue}{13 \equiv 43 \equiv 15\cdot1 +10\cdot1 +6\cdot3 \:\text{mod}\: 30} \\ 14 \\ 15 \\ 16 \\ \color{red}{17 \equiv 47 \equiv 15\cdot1 +10\cdot2 +6\cdot2 \:\text{mod}\: 30} \\$
$ 18 \\ \color{blue}{19 \equiv 15\cdot1 +10\cdot1 +6\cdot4 \:\text{mod}\: 30} \\ 20 \\ 21 \\ 22 \\ \color{red}{23 \equiv 15\cdot1 +10\cdot2 +6\cdot3 \:\text{mod}\: 30} \\$
$ 24 \\ \color{blue}{25} \\ 26 \\ 27 \\ 28 \\ \color{red}{29 \equiv 15\cdot1 +10\cdot2 +6\cdot4 \:\text{mod}\: 30} \\$
I had to say, I was suspicious when I read the question but I coded up the problem and up to at least $n=10$ it definitely works.
Edit: I found a proof! It works. Check out the details below.
The proof consists of two main steps: we first prove that the sum $r_1 q_1 + \cdots + r_n q_n$ can never be divided by $p_i$ for any $i$ between $1$ and $n$. After that, we will show that $x_2 = p_{n+1}$.
To prove the first part, let's first forget about the modulo $p_1p_2\cdots p_n$ term for a moment. Now, note that both $q_i$ and $r_i$ are not divisible by $p_i$ and all other $q_i$ are divisible by $p_i$. Hence, our sum $$r_1q_1 + \cdots + r_n q_n = r_i q_i (\neq 0) \mod p_i$$ can never be divisible by $p_i$. Adding a multiple of $p_1\cdots p_n$ (which is divisible by $p_i$) doesn't change this fact. Hence, $$\Big(r_1 q_1 + \cdots + r_n q_n\mod (p_1\cdots p_n)\Big) \neq 0 \mod p_i$$ for any $i$ between $1$ and $n$. Summarizing, the first $n$ primes $p_1$, $p_2$, $\dots$ ,$p_n$ will never be divisors of our sum. Now, the question remains: might it be divisible by $p_{n+1}$ for example? We cannot exclude this! But this does wrap up the first part of the proof.
Lemma There exist choices $(r_1,\dots,r_n)$ and $(r_1',\dots,r_n')$ such that $$ r_1 q_1 + \cdots + r_n q_n = 1\mod (p_1p_2\cdots p_n) $$ and $$ r_1 q_1 + \cdots + r_n q_n = p_{n+1}\mod (p_1p_2\cdots p_n). $$
Proof This lemma is actually an application of the Chinese Remainder Theorem. This theorem states that given a sequence $$(a_1,\dots,a_n)\in \prod_{i=1}^{n}\mathbb{F}_{p_i}$$ is uniquely related to an $a\in\mathbb{F}_{\prod_{i=1}^{n} p_i}$ where I use the notation $\mathbb{F}_z$ to represent the group related to calculating modulo $z$.
We actually know that $(1,1,\dots,1)$ is related to $1$ but we don't know exactly what is the sequence which is related to $p_{n+1}$. It turns out it is not necessary to know this sequence to proof its existence! Let's take now arbitrary values $z_1,\dots,z_n$ which satisfy the same conditions as the $r_i$, $r_i'$. Let's simplify our expression now modulo $p_i$
$$ z_1 q_1 + \cdots + z_n q_n = z_i q_i \mod p_i $$
Since $p_i$ is prime, we know that $c q_i$ for $c\in\{1,\dots,p_i-1\}$ actually generates the complete group, i.e., $$ \{c q_i \mod p_i:\ c\in\{1,\dots,p_i-1\}\} = \{1,2,\dots,p_i-1\}.$$ This essentially means that we can make the right-hand side equal to almost any number in $\prod_{i=1}^{n}\mathbb{F}_{p_i}$. To be precise,
$$ \prod_{i=1}^{n}\{z_1 q_1 + \cdots + z_n q_n \mod p_i:\ \forall j:\ 1\leq z_j\leq p_j-1\} \\ = \prod_{i=1}^{n}\{z_i q_i \mod p_i:\ 1\leq z_i\leq p_i-1\} = \prod_{i=1}^{n} (\mathbb{F}_{p_i}\setminus\{0\}). $$ A slight adaptation of the standard Chinese Remainder Theorem now gives us that
$$ \{z_1 q_1 + \cdots + z_n q_n \mod (p_1\cdots p_n):\ \forall j:\ 1\leq z_j\leq p_j-1\} = \mathbb{F}_{\prod_{i=1}^{n} p_i}\setminus A $$
where $A$ is the set of all multiples of $0,\ p_1,\ p_2,\ \dots,\ p_n$.
Now, let's translate this to English. We see that $1$ is not an element of $A$ and, hence, there exists a sequence $(z_1,\dots,z_n)$ such that
$$ z_1 q_1 + \cdots + z_n q_n = 1 \mod (p_1\cdots p_n)$$
and we simply take $r_i = z_i$. Moreover, the next element which is not part of $A$ is $p_{n+1}$ and hence there exist a sequence $(w_1,\dots,w_n)$ such that
$$ w_1 q_1 + \cdots + w_n q_n = p_{n+1} \mod (p_1\cdots p_n) $$
and we take $r_i'=w_i$. This completes the proof of the lemma.
Now, we have dealt with the most difficult part and it is not too difficult to finish the proof. For the sake of completeness, let $s = r_1 q_1 + \cdots + r_n q_n\mod (p_1p_2\cdots p_n)$ such that $s< p_{n+1}^2$ and let's assume it is composite. We have proven above that $s$ is not divisible by $p_1,\ p_2,\ \dots,\ p_n$. This means that the first candidate prime factor is actually $\geq p_{n+1}$. However, since $s$ is composite, it has a second prime factor and this also needs to be $\geq p_{n+1}$. Thus $s\geq p_{n+1}^2$ which is a contradiction. This completes the overall proof!
Extra note: we have developed a way of constructing the first $n$ primes. However, since it is not clear how the sequence $(r_1',\dots,r_n')$ is chosen in practice, the method is not particularly computationally efficient to put it mildly.
Final note: Using the same strategy as above, it is not too difficult to prove that in fact, for any $n\geq 4$, we can write any prime number between $p_n$ and $p_{n+1}^2$ in the form $$ r_1 q_1 + \cdots + r_n q_n \mod(p_1 p_2\cdots p_n)$$ which is quite an interesting corollary! (For $n=3$, this is also true if we forget about the $\mod 30$ term)