Random Number Generator

Random Numbers

The generation of random numbers is important in many applications like simulations, cryptography, sampling and mostly in statistics. A sequence of numbers is random when it does not have a recognizable pattern in it or in other words if it is non-deterministic. Although non-deterministic random numbers are ideal, the computer generated, deterministic random numbers can be statistically “random enough”. These random numbers are named as pseudo-random numbers and can have easily identifiable patterns if the algorithm is not chosen wisely. Sometimes, you need to generate a cryptographically secure random number, for example, for creating a random password. For this scenario, you should use a class derived from the System.Security.Cryptography.RandomNumberGenerator. For example, you can use System.Security.Cryptography.RNGCryptoServiceProvider. CryptoRandom brings with it a performance cost. While Random’s implementation does not produce cryptographically strong random numbers, it is extremely fast when compared to RNGCryptoServiceProvider. Roughly, random is over 100 times faster than CryptoRandom.

Copyright © All Rights Reserved - C# Learners