libraries needed :-
- python3.
- qiskit .
- qiskit.visualization.
- array from numpy.
- random.
We take a random number from the listlist1=[0,1,2,3]
usingrandom.choice(list1)
We create a set of 4-bit numbers based on the random number.
A coresponding QuantumCircuit is created.
Few simple gates are applied to get a result.
The result is simulated using *Aer* simulator and is viewed on a histogram using
plot_histogram
Here is you what you can expect:-
Random number | 4-bit value | Result |
---|---|---|
0 | 0011 | 0100 |
1 | 1010 | 0011 |
2 | 0101 | 0110 |
3 | 1100 | 0001 |