! pip install qiskit

from qiskit import QuantumCircuit, Aer, IBMQ, execute
from qiskit.tools.monitor import job_monitor
import math

def superpose(n):
    circuit = QuantumCircuit(n,n)
    for i in range(0,n):
        circuit.h(i)
    circuit.measure(range(n),range(n))
    return circuit

sample = superpose(6)
sample.draw('mpl')

def qrandom_sim(a,b):
    n = math.ceil(math.log2(b))
    circuit = superpose(n)
    simulator = Aer.get_backend('qasm_simulator')
    result = execute(circuit,backend = simulator, shots = 1).result()
    v = int(list(result.get_counts(circuit).keys())[0],2)
    return v%(b-a+1)+a

r = qrandom_sim(2,20)
print(r)

IBMQ.load_account()

def qrandom(a,b):
    n = math.ceil(math.log2(b))
    circuit = superpose(n)
    provider = IBMQ.get_provider('ibm-q')
    qcomp = provider.get_backend('ibmq_16_melbourne')
    job = execute(circuit,backend = qcomp,shots = 1)
    job_monitor(job)
    result = job.result()
    v = int(list(result.get_counts(circuit).keys())[0],2)
    return v%(b-a+1)+a

r = qrandom(20,40)
print(r)

