Parallel quantum random number generator (QRNG) sample

This sample demonstrates how to use Q# and the Azure Quantum service together to build a quantum random number generator (QRNG). In particular, this sample uses a register of qubits rather than a single qubit to draw random numbers several bits at a time, avoiding the need for intermediate measurement.

This sample is implemented as a standalone executable, such that no C# or Python host is needed. The program takes one command-line option, --n-qubits, to control the number of qubits used to sample a random number.

This sample can be run in one of three different ways, depending on your preferred environment:

  • Q# standalone at the command-line
  • Q# standalone from Jupyter Notebook
  • Q# from a Python host program

Q# standalone command-line

Running the sample on a local simulator

dotnet run -- --simulator QuantumSimulator --n-qubits=4

Running the sample on the Azure Quantum service

Make sure that you have created and selected a quantum workspace, and then run the following at the command line, substituting TARGET with the target that you would like to run against (e.g.: ionq.qpu or quantinuum.hqs-lt):

az quantum execute --target-id TARGET -- --n-qubits=4

For a full list of available QIO and quantum computing targets, run:

az quantum target list --output table

Q# with Jupyter Notebook

Make sure that you have followed the Q# + Jupyter Notebook quickstart for the Quantum Development Kit, and then start a new Jupyter Notebook session from the folder containing this sample:

cd parallel-qrng
jupyter notebook

Once Jupyter starts, open the ParallelQrng.ipynb notebook and follow the instructions there.

Q# with a Python host program

Make sure that you have followed the Q# + Python quickstart for the Quantum Development Kit, and then run Python from within the folder containing this sample.

The Python host program takes as command-line arguments the resource, location, and target IDs to submit your Azure Quantum service job to. When running the command below, make sure to replace the example resource ID with the ID for your workspace, replace LOCATION with the location for your workspace, and replace TARGET_ID with the target that you would like to submit to (e.g.: ionq.simulator). The information for resource ID, location, and available targets can be found in the Azure Portal.

cd parallel-qrng/python-host
python parallel_qrng.py /subscriptions/SUBSCRIPTION_ID/resourceGroups/RESOURCE_GROUP_NAME/providers/Microsoft.Quantum/Workspaces/WORKSPACE_NAME LOCATION TARGET_ID

For a full list of available QIO and quantum computing targets, run:

az quantum target list --output table

⚠️ This sample makes use of paid services on Azure Quantum. The cost of running this sample with the provided parameters on IonQ in a Pay-As-You-Go subscription is approximately $1-$2 USD (or the equivalent amount in your local currency). This quantity is only an approximate estimate and should not be used as a binding reference. The cost of the service might vary depending on your region, demand and other factors.

Manifest