5.2. System.Random class

The System.Random class serves as a pseudo-random number generator. We can use this class to get a random number – either decimal or whole random numbers. To generate such numbers we can use the Next()method to return a random number, NextDouble() to return a Double random number between 0.0 and 1.0 (the number will be greater than or equal to 0.0 and less than 1.0), or NextBytes(Byte() ) to fill the elements of a specified array of bytes with random numbers. The following example illustrates how to use these methods to generate random numbers – both Double and Integers:

 '--------------------------------------- ' .NET System.Random Class Demo '--------------------------------------- Imports System Module Cons Sub Main() ...

Get A Programmer's Guide to .NET 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.