Generating Random Numbers
A fairly common task is to generate random numbers (for example, to create a random permutation of objects in a collection, to write a lottery application, to generate test input sequences). The System
namespace contains a Random
class that’s designed for this purpose, producing what’s known as a pseudo-random sequence.
Security, Security, Security
It can’t be emphasized enough that the Random
class is not well suited for use in a security-critical context (for example, to provide cryptographic strength random numbers) in part due to its pseudo-random (and hence predictable) nature.
For such uses, the System.Security.Cryptography
namespace should be put into action, with its RandomNumberGenerator
base class and derive ...
Get C# 4.0 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.