47. Cryptographic pseudorandom numbers

Several of the solutions in earlier chapters used the Random class to generate random numbers. In fact, those numbers are not really random at all. They use easily predictable algorithms to generate sequences of numbers that are random enough to simulate moving bubbles and random walks, but they are not cryptographically secure. Technically that means an attacker who learns some of the numbers in a sequence of random values may be able to predict the values that follow with some success. Even a small advantage at prediction may give an attacker a way to break an encryption system based on the random number generator.

To prevent that from happening, you can use a Cryptographically Secure Pseudorandom Number Generator (CSPRNG), which is also called a Cryptographic Pseudorandom Number Generator (CPRNG).

Note that even these methods are not truly random, so they are still called pseudorandom techniques.

For this problem, create a method that uses the .NET cryptographic library to generate long integers between inclusive lower and exclusive upper bounds. (Similar to the way the Random class's Next method generates integers within a range.)

Make the test program generate an indicated number of random values and then display each value's number of occurrences, fraction of occurrences, and error (fraction minus expected fraction of occurrences), as shown in the following screenshot:

The error values will not be zero, but they should grow smaller when you perform more trials. They should also change relative positions if you click Generate repeatedly. For example, if the fraction or error for the value 8 is always greater than the results for the other values, then the values are not uniformly distributed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.152.254