ID 768738
Date 12/16/2022
Public

## Example of Using Pseudorandom Number Generation Functions

### Find Pseudorandom Co-primes

void FindCoPrimes(void){
int size;

// define Pseudo Random Generator (default settings)
ippsPRNGGetSize(&size);
IppsPRNGState* pPrng = (IppsPRNGState*)(new Ipp8u [size] );
ippsPRNGInit(160, pPrng);

// define 256-bits Big Numbers X and Y
const int bnBitSize = 256;
IppsBigNumState* bnX = New_BN(bnBitSize/32);
IppsBigNumState* bnY = New_BN(bnBitSize/32);

// define temporary Big Numbers GCD and 1
IppsBigNumState* bnGCD = New_BN(bnBitSize/32);
Ipp32u one = 1;
IppsBigNumState* bnOne = New_BN(1, &one);

// generate pseudo random X and Y
// while GCD(X,Y) != 1
Ipp32u result;
int counter;
for(counter=0,result=1; result; counter++) {
ippsPRNGen_BN(bnX, bnBitSize, pPrng);
ippsPRNGen_BN(bnY, bnBitSize, pPrng);
ippsGcd_BN(bnX, bnY, bnGCD);
ippsCmp_BN(bnGCD, bnOne, &result);
}

cout <<"Coprimes:" <<endl;
Type_BN("X: ", bnX); cout <<endl;
Type_BN("Y: ", bnY); cout <<endl;
cout <<"were fond on " <<counter <<" attempt" <<endl;

delete [] (Ipp8u*)pPrng;
delete [] (Ipp8u*)bnX;
delete [] (Ipp8u*)bnY;
delete [] (Ipp8u*)bnGCD;
delete [] (Ipp8u*)bnOne;
}