We're required to implement Blum Blum Shub Algorithm in a pseudo random number generator. I tried searching for implementations in c# to get an idea but was unsuccessful. Some methods we're required to implement are not clear enough (or maybe I'm not getting exactly what they're asking).

Anyone could provide some help with either the code or maybe an example in a similar fashion? I have a harder time grasping concepts from text.Any help would be greatly accepted!

First, I tried following the logic of the question. With little progress, I began searching on-line for better explanations and possibly finding implementations to better understanding. Finally, I attempted to fill in some of the requested methods with what I thought made sense.

```
static long seed = 6367859;
static long p = 3263849;
static long q = 1302498943;
static long m = p*q;
// Generates a random bit i.e. 0 or 1 using the Blum Blum Shub Algorithm and the Least Significant Bit
private byte generateRandomBit(){ }
// Method to generate a single positive 32 bit random number using the Blum Blum Shub Algorithm.
// The generateRandomBit() method is used to generate the random bits that make up the random number
// Not complete!!
public int GenerateNextRandomNumber()
{
int nextRandomNumber = (int)((p * seed + q) % m);
seed = nextRandomNumber;
return nextRandomNumber;
}
// Generates a random number between min and max.
// The GenerateNextRandomNumber() method must be used to generate the initial random number which must then be manipulated (if necessary) to be between min and max
public int GenerateNextRandomNumber(int min, int max){ }
// Uses the GenerateNextRandomNumber Method to generate a sequence of Random Numbers between the minimum and the maximum value using the Blum Blum Shub Algorithm
public int[] GenerateRadmonSequence(int n, int min, int max)
{
int[] sequence = new int[n];
for (int i = 0; i < n; i++)
{
int randNum = Math.Abs(GenerateNextRandomNumber());
randNum = min + randNum % (max + 1 +- min);
sequence[i] = randNum;
}
return sequence;
}
```

The result should be to generate a sequence of numbers from min to max.

No, you cannot use longs for this type of RNG, it pretty much requires arbitrary precision math. And what you implemented is actually looks like Linear Congruential Generator, not Blum Blum Shub algorithm.

Here is the code to get you going, .NET Core 2.2, x64 Win10. Using BigInteger, proper algorithm I believe, and parity to get next random bit. You could use least significant bit for random bit as well.