# How it Works
The API3 QRNG service is implemented using the Airnode request–response protocol contract, AirnodeRrpV0 (opens new window), to acquire a random number.
Upon request, Airnode calls a designated API operation and
acquires a random number and then delivers it on-chain, via the
protocol contract, to a requester.
In the diagram below a requester (smart contract) submits a request for a random
AirnodeRrpV0. Airnode gathers the request from the
protocol contract, gets the random number from an API operation and sends it
AirnodeRrpV0. Once received,
AirnodeRrpV0 performs a callback to the
requester with the random number.
AirnodeRrpV0 for a random number is the same as any other Airnode
request. Read more about how a requester
accesses an Airnode to acquire data from API
Using the QRNG service is free, meaning there is no subscription fee to pay. There is a gas cost incurred on-chain when Airnode places the random number on-chain in response to a request, which the requester needs to pay for.
A requester (smart contract) calls the QRNG service using the request–response
protocol (RRP) implemented by the on-chain
AirnodeRrpV0 contract. The
RrpRequesterV0.sol (opens new window)
is meant to be inherited by any requester that will be making requests to
AirnodeRrpV0. It is part of the NPM
@api3/airnode-protocol (opens new window)
In practice, the requester implements two functions that are specific to requesting and receiving a random number from the QRNG service. Consider the following flow (extracted from the QRNG example contract (opens new window)) to understand how to call for a random number.
airnodeRrp.makeFullRequest()to request a random number, which in turn returns a
requestIdis stored in the mapping
expectingRequestWithIdToBeFulfilledfor reference in the callback function.
fulfillUint256is the callback to receive the random number from the QRNG service. The callback contains the
requestIdreturned by the initial request and the
data, which contains the random number. The
requestIdis verified and removed from the mapping