O'Reilly logo

A Programmer's Guide to .NET by Alexei Fedorov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required