/// <summary> /// Generates a pool of <paramref name="count"/> true random ints of n <paramref name="bits"/>. /// It makes an asynchronous operation so the value is returned through /// the callback <see cref="OnRandomFloatPoolGenerated"/>. /// </summary> /// <param name="bits">The number of bits used to generate the int</param> /// <param name="count">The amount of ints generated</param> /// <param name="onRandomIntPoolGenerated">The callback called when the pool is available</param> public void GenerateIntNbitsPool(int bits, int count, OnRandomIntPoolGenerated onRandomIntPoolGenerated) { executionSession.RequestBackendConfig((backendConfig) => { int codeRegs = Mathf.Min(backendConfig.qubitsCount, bits); int shotsNeededPerItem = Mathf.CeilToInt((float)bits / codeRegs); QASMExecutable qasmExe = new QASMExecutable(RandomNRegisterCode(codeRegs), shotsNeededPerItem * count); executionSession.ExecuteCodeRawResult(qasmExe, (response) => { List <int> pool = new List <int>(); for (int i = 0; i < count; i++) { int rng = 0; int padding = i * shotsNeededPerItem; for (int j = 0; j < shotsNeededPerItem; j++) { rng += response.rawResult[j + padding] << (j * codeRegs); } rng = ClampToBits(rng, bits); pool.Add(rng); } onRandomIntPoolGenerated(pool); }); }); }
/// <summary> /// Generates a pool of <paramref name="count"/> true random ints. /// It makes an asynchronous operation so the value is returned through /// the callback <see cref="OnRandomIntPoolGenerated"/>. /// </summary> /// <param name="count">The amount of ints generated</param> /// <param name="onRandomIntPoolGenerated">The callback called when the pool is available</param> public void GenerateInt32Pool(int count, OnRandomIntPoolGenerated onRandomIntPoolGenerated) { GenerateIntNbitsPool(32, count, onRandomIntPoolGenerated); }