# Are there patterns in the numbers created with qrng by entangled qubits?

I want to examine the graph of 2 sets consisting of 1000 numbers created with quantum random number generator which were created by entangled qubits and see if there is a pattern in the randomly generated number series.

How can I do this with Q#?

So by doing that I think,I can entangle two qubits in Sample Quantum Random Number Generator

operation SampleQuantumRandomNumberGenerator() : Result {
// Allocate two qubits
using ((q1, q2) = (Qubit(), Qubit()))  {
// Prepare Bell state (|00⟩ + |11⟩) / sqrt(2) on them
H(q1);
CNOT(q1, q2);
// The measurement results are going to be correlated: you get 0,0 in 50% of the cases and 1,1 in 50%
return (MResetZ(q1) == Zero ? 0 | 1,
MResetZ(q2) == Zero ? 0 | 1);
}


But how can I use qubits ( qs(0) for one set qs(1) for one set ) in here for getting 2 sets consisting of 1000 numbers between 0 and 100 ?

operation SampleRandomNumberInRange(max : Int) : Int {
mutable bits = new Result[0];
for (idxBit in 1..BitSizeI(max)) {
set bits += [SampleQuantumRandomNumberGenerator()];
}
let sample = ResultArrayAsInt(bits);
return sample > max
? SampleRandomNumberInRange(max)
| sample;
}

@EntryPoint()
operation SampleRandomNumber() : Int {
let max = 100;
Message($"Sampling a random number between 0 and {max}: "); return SampleRandomNumberInRange(max); }  • If it were me, I'd pull the data into Matlab. That kind of analysis would be trivial there. I'm not sure exactly what sort of correlation you're looking for, but for anything like this I always start by plotting the data in both the time and frequency domains to get a quick visual sense of the data set and to catch any obvious anomalies. May 22 '20 at 13:14 • quantum random number generator is needed for it May 22 '20 at 13:14 • Sorry, I think I misunderstood. You need to write a QRNG in Q#? May 22 '20 at 13:15 • Yeah there is a QRNG at Q# but I want to make it with 2 qubits which are entengled and each of them generates random numbers May 22 '20 at 13:17 • now I get it, the formulas are not understood when looking on the phone :) May 23 '20 at 8:50 ## 1 Answer You can base your code on this Q# sample, adjacent to the one you've been looking at. The simplest thing is generating random bits 0 or 1 that are perfectly correlated; you can do that using Bell state $$|\Phi^+\rangle$$: operation GenerateCorrelatedRandomNumbers () : (Int, Int) { // Allocate two qubits using ((q1, q2) = (Qubit(), Qubit())) { // Prepare Bell state (|00⟩ + |11⟩) / sqrt(2) on them H(q1); CNOT(q1, q2); // The measurement results are going to be correlated: you get 0,0 in 50% of the cases and 1,1 in 50% return (MResetZ(q1) == Zero ? 0 | 1, MResetZ(q2) == Zero ? 0 | 1); } } @EntryPoint() operation SampleCorrelatedRandomNumbers () : Unit { for (i in 1 .. 10) { Message($"{GenerateCorrelatedRandomNumbers()}");
}
}


This will give you

(0, 0)
(1, 1)
(1, 1)
...
(0, 0)


If you want the bits to be perfectly anti-correlated, you can use the state $$|\Psi^+\rangle$$:

    using ((q1, q2) = (Qubit(), Qubit()))  {
// Prepare Bell state (|10⟩ + |01⟩) / sqrt(2) on them
H(q1);
CNOT(q1, q2);
X(q1);
// The measurement results are going to be correlated: you get 0,1 in 50% of the cases and 1,0 in 50%
return (MResetZ(q1) == Zero ? 0 | 1,
MResetZ(q2) == Zero ? 0 | 1);
}


• If you want your bits to still be correlated but yield outcomes with different probabilities than 50%/50%, you can use a rotation gate Ry instead of H to prepare a state $$\alpha |00\rangle + \beta |11\rangle$$ - that will give you (0,0) with probability $$\alpha^2$$ and (1,1) with probability $$\beta^2$$ (you don't need to use complex coefficients if you only care about simple measurement probabilities).
• If you want your bits to be correlated strongly but not perfectly, you can prepare a superposition of all basis states with different amplitudes - for example, something like $$\frac{1}{\sqrt{20}}(3|00\rangle + |01\rangle + |10\rangle + 3|11\rangle)$$ will give you equal bits in 90% of the cases and distinct bits in 10% of the cases.
• You can learn more about Q# programming and preparing quantum states using Q# in the Quantum Katas - the first set of tutorials and exercises focuses on the basic constructs like allocating qubits and applying gates and preparing states on them.