Giter Club home page Giter Club logo

qrng's Introduction


DOI

qRNG is an open-source quantum random number generator written in python. It achieves this by using IBM's QISKit API to communicate with any one of their publicly accessible quantum computers:

  • ibmq_armonk 1 qubit
  • ibmq_london 5 qubits
  • ibmq_burlington 5 qubits
  • ibmq_essex 5 qubits
  • ibmq_ourense 5 qubits
  • ibmq_vigo 5 qubits
  • ibmqx2 5 qubits
  • ibmq_qasm_simulator 32 qubits (simulated)
  • qasm_simulator 8 qubits (simulated)

Note that you need to input your IBMQ API token (make an IBMQ account here) to access any of these quantum computers/simulators, except for qasm_simulator which can be accessed locally via the instructions below.

Installation

You can use the pip package manager to install the current release of qRNG:

pip install qrng

Upgrading is as simple as:

pip install qrng -U

Tutorial

Now you can try generating your first random number. First open python in the shell or use an IDE:

$ python

Now let's connect qRNG to our IBMQ account and generate some numbers:

>>> import qrng
>>> qrng.set_provider_as_IBMQ('YOUR_IBMQ_TOKEN_HERE') #the IBMQ API token from your dashboard
>>> qrng.set_backend('ibmq_london') #connect to the 5 qubit 'ibmq_london' quantum computer
>>> qrng.get_random_int32() #generate a random 32 bit integer
3834878552
>>> qrng.get_random_float(0,1) #generate a random 32 bit float between 0 to 1
0.6610504388809204

If you don't need or want to use IBM's actual quantum computers, you can instead just use the default backend like so:

>>> import qrng
>>> qrng.set_provider_as_IBMQ('') #empty string denotes local backend which can only use 'qasm_simulator'
>>> qrng.set_backend() #no args defaults to `qasm_simulator`
>>> qrng.get_random_int64() #generate a random 64 bit integer
10110319200202513540
>>> qrng.get_random_double(0,1) #generate a random 64 bit double between 0 to 1
0.9843570286395331

What is Random Number Generation?

There are a variety of applications that require a source of random data in order to work effectively (e.g. simulations and cryptography). To that end, we make use of random number generators (RNGs) to generate sequences of numbers that are, ideally, indistinguishable from random noise.

There are two types of RNGs: Pseudo-RNGs (PRNGs) and True RNGs (TRNGs). Pseudo-RNGs, while not truly and statistically random, are used in a variety of applications as their output is 'random enough' for many purposes.

For a True RNG, however, an actual piece of hardware is required to measure some random process in the real world as no computer program could suffice due to being deterministic in nature. These devices vary from apparatuses that measure atmospheric noise to pieces of radioactive material connected via USB.

Why Quantum?

Modern physics has shown us that there are really only two types of events that can happen in the universe: the unitary transformation of a quantum system, and quantum wavefunction collapse (i.e. measurement). The former being a totally deterministic process and the latter being a random one.

Indeed, all randomness in the universe (as far we know) is the result of the collapse of quantum systems upon measurement. In a sense, this is randomness in its purest form and the underlying source of it in any TRNG.

The point of this package then, besides it being a fun side project, is to cut out the middle man entirely, whether it be a radioactive isotope or the thermal noise in your PC, and simply measure an actual quantum system. For example, we can prepare the following state in a quantum computer:

There is a 50-50 chance of measuring the above state as a 0 or 1 and we can continually iterate this process for as many random bits as we require. Note that while such a simple algorithm doesn't require a full-blown quantum computer, there are some random algorithms that do.

Practicality

Of course, while the numbers generated from a quantum computer are amongst the most random, the practicality of connecting to one of IBM's quantum computers to generate a large amount of these numbers is nonexistent. For most real world use cases that require such high-caliber random numbers, an off the shelf hardware RNG would suffice. The purpose of this package is thus to provide a working example of how a real cloud based quantum random number generator may operate.

qrng's People

Contributors

jiihwan-kim avatar jiihwankim avatar ozaner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

qrng's Issues

Error on running short code

Here is the short code. I just want to generate some QRNGs for a small project.

import qrng

for i in range(100):
    print(qrng.get_random_int(0,9))

Traceback (most recent call last):
File "C:\Users[USER]\Documents\python\qrngarraymakaer.py", line 4, in
print(qrng.get_random_int(0,9))
File "C:\Users[USER]\AppData\Local\Programs\Python\Python37\lib\site-packages\qrng_init_.py", line 77, in get_random_int
result = int(get_bit_string(n),2)
File "C:\Users[USER]\AppData\Local\Programs\Python\Python37\lib\site-packages\qrng_init_.py", line 67, in get_bit_string
_request_bits(n-len(bitCache))
File "C:\Users[USER]\AppData\Local\Programs\Python\Python37\lib\site-packages\qrng_init
.py", line 60, in _request_bits
job = qiskit.execute(_circuit, _backend, shots=1)
NameError: name '_backend' is not defined

If I try to reproduce results from the README code it returns an error

Code I used:

import qrng
qrng.set_provider_as_IBMQ("TOKEN GOES HERE") #the IBMQ API token from your dashboardqrng.set_backend('ibmq_london') #connect to the 5 qubit 'ibmq_london' quantum computer
qrng.get_random_int32() #generate a random 32 bit integer
3834878552
qrng.get_random_float(0,1) #generate a random 32 bit float between 0 to 1
0.6610504388809204

TypeError Traceback (most recent call last)
in
----> 1 import qrng
2 qrng.set_provider_as_IBMQ('93ed74ab24bd54d2596d269986ca8c4b2086704c07cb815c977590b1410b23a315ea83470e3bb3f3cc766e5170b7ae7613344218010fae2a3671497d17b4b906') #the IBMQ API token from your dashboardqrng.set_backend('ibmq_london') #connect to the 5 qubit 'ibmq_london' quantum computer
3 qrng.get_random_int32() #generate a random 32 bit integer
4 3834878552
5 qrng.get_random_float(0,1) #generate a random 32 bit float between 0 to 1

/usr/local/lib/python3.8/dist-packages/qrng/init.py in
130 # Returns a random complex with both real and imaginary parts
131 # from the given ranges. If no imaginary range specified, real range used.
--> 132 def get_random_complex_rect(real_min: float = 0, real_max: float = 0, img_min: float | None = None, img_max: float | None = None) -> complex:
133 """
134 Returns a random complex number with:

TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

Measurement Device Independent qRNG is needed

Since any noise in qiskit's measurement can be interpreted as an effect from eavesdropper, we need to develop qRNG that can ensure its randomness.
From MDIqRNG, in spite of noisy environment, not only we can ensure its randomness but also we can suggest its randomness numerically.

1703.03330.pdf

When import qrng module I get ModuleNotFoundError

Hi,
I am trying to play a bit with the qRNG module based on the provided documentation, but from unknown reason I keep get the following error:

import qrng

IBM_TOKEN = 1111*******
qrng.set_provider_as_IBMQ(IBM_TOKEN ) #empty string denotes local backend which can only use 'qasm_simulator'
qrng.set_backend('ibmq_london') #no args defaults to `qasm_simulator`
print(qrng.get_random_int32()) #generate a random 64 bit integer 10110319200202513540
rand_int = qrng.get_random_double(0,1) #generate a random 64 bit double between 0 to 1 0.9843570286395331
print(rand_int)

Once I try to run the script I get the following error:

Exception has occurred: ModuleNotFoundError
No module named 'qiskit'

Any chance you familiar with that issue?

IDE: vscode - latest version 
Windows operation system

Multiple shots

Hi! Can more than one shot be used to create a sequence of bits? Because it takes too long to wait for each job to be done on a quantum computer.

randomness of qRNG

Hi,
This may not be an issue, but a question regarding the quality of the qRNG?
This is an interesting project demonstrating the application of the quantum bits.
Have you tested the "randomness" of the qRNG? How is it compared to the random numbers from deterministic processes?
Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.