예제 #1
0
    /// <summary>
    /// Generates a true random int of n <paramref name="bits"/>.
    /// It makes an asynchronous operation so the value is returned through
    /// the callback <see cref="OnRandomIntGenerated"/>
    /// </summary>
    /// <param name="bits">The number of bits used to generate the int</param>
    /// <param name="onRandomFloatGenerated">The callback called when the int is available</param>
    public void GenerateIntNbits(int bits, OnRandomIntGenerated onRandomIntGenerated)
    {
        executionSession.RequestBackendConfig((backendConfig) => {
            int codeRegs           = Mathf.Min(backendConfig.qubitsCount, bits);
            int shotsNeeded        = Mathf.CeilToInt((float)bits / codeRegs);
            QASMExecutable qasmExe = new QASMExecutable(RandomNRegisterCode(codeRegs), shotsNeeded);

            executionSession.ExecuteCodeRawResult(qasmExe, (response) => {
                int rng = 0;
                for (int i = 0; i < response.rawResult.Count; i++)
                {
                    rng += response.rawResult[i] << (i * codeRegs);
                }
                rng = ClampToBits(rng, bits);
                onRandomIntGenerated(rng);
            });
        });
    }
예제 #2
0
 /// <summary>
 /// Generates a true random 32 bit int.
 /// It makes an asynchronous operation so the value is returned through
 /// the callback <see cref="OnRandomIntGenerated"/>
 /// </summary>
 /// <param name="onRandomIntGenerated">The callback called when the int is available</param>
 public void GenerateInt32(OnRandomIntGenerated onRandomIntGenerated)
 {
     GenerateIntNbits(32, onRandomIntGenerated);
 }
예제 #3
0
 /// <summary>
 /// Generates a true random 16 bit int.
 /// It makes an asynchronous operation so the value is returned through
 /// the callback <see cref="OnRandomIntGenerated"/>
 /// </summary>
 /// <param name="onRandomIntGenerated">The callback called when the int is available</param>
 public void GenerateInt16(OnRandomIntGenerated onRandomIntGenerated)
 {
     GenerateIntNbits(16, onRandomIntGenerated);
 }