1
$\begingroup$
from qiskit import *


def random_bitstring_generator(bit_number, backend):
   

    bitstring = ""

    one_qubit_random_bit_generator_circuit = QuantumCircuit(1, 1)
    one_qubit_random_bit_generator_circuit.h(0)
    one_qubit_random_bit_generator_circuit.measure(0, 0)

    for _ in range(bit_number):
        counts = execute(one_qubit_random_bit_generator_circuit, backend, shots=8192).result().get_counts()
        bit = list(counts.keys())[0]  
        bitstring += bit

    return bitstring


backend = BasicAer.get_backend('qasm_simulator')

print(random_bitstring_generator(1024, backend))
  1. How can i insert a noise model replicating IBM melbourne quantum machine for the circuit execution on simulator
  2. Is there a way to be able export the sequence received as output to an text/csv file
$\endgroup$
0
$\begingroup$
  1. https://qiskit.org/documentation/tutorials/simulators/2_device_noise_simulation.html
  2. bitstring is a string, you can manipulate it and save it using Python commands.
$\endgroup$
0
$\begingroup$
  1. Add this code to your current code. This creates a simulator backend with the noise model from ibmq_16_melbourne.
from qiskit.providers.aer import QasmSimulator

provider = IBMQ.load_account()
ibmq_melbourne = provider.get_backend('ibmq_16_melbourne')
backend = QasmSimulator.from_backend(ibmq_melbourne)

print(random_bitstring_generator(1024, backend))
  1. Your output is already a string. If you want to dump that in a file, you can do this (this is a general Python question, not related to Qiskit:
with open("output.txt", "w") as text_file:
    text_file.write(random_bitstring_generator(1024, backend))

Note: If you are trying generate a random number generator, probably you should have a look to qiskit.providers.ibmq.random.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.