Statsar Statistics Library

v1.0.1 for .NET

Product Guide



More Information...

Valid XHTML


Mersenne Twister Random Example (VB.NET)

[VB.NET]
' COPYRIGHT(C), SIMPLEXAR SOFTWARE LIMITED, 2006-2008.
' All rights reserved.
'
' Use of this copyright notice is precautionary only, and does not imply
' publication or disclosure. The content of this work contains confidential
' and proprietary information of Simplexar Software Limited. Any duplication,
' modification, distribution, or disclosure in any form, in whole, or in part,
' is strictly prohibited without express prior written permission.

' Get namespaces.
Imports System
Imports Simplexar.Statsar
Imports Simplexar.Statsar.RandomNumbers

' Start namespace.
Namespace Simplexar.Examples.Statsar

    ' This example illustrates how to generate random deviates using
    ' the Mersenne twister random number generator algorithm.
    Module Example

        ' The application entry point.
        Public Sub Main()
            Try
                RunExample()
            Catch exception As Exception
                Console.WriteLine(exception)
            End Try
            Console.WriteLine("Press ENTER to terminate.")
            Console.ReadLine()
        End Sub

        Private Sub RunExample()

            ' Get a Mersenne twister generator implementing the MT19937
            ' algorithm. MT19937 is the newer algorithm and is more commonly
            ' used in random number generator applications.
            Dim random As MersenneTwister = RandomGenerators.GetMT19937()

            ' Get a non-negative random number.
            Console.WriteLine( _
                "Non-negative integer: {0}", random.Next())

            ' Get a non-negative random number less than
            ' the specified maximum.
            Console.WriteLine( _
                "Non-negative integer less than 10: {0}", random.Next(10))

            ' Get a random number greater or equal to the specified
            ' minimum and less than the specified maximum.
            Console.WriteLine( _
                "Integer greater or equal to 90 and less than 100: {0}", _
                random.Next(90, 100))

            ' Get a random number greater or equal to 0 and less than 1.
            Console.WriteLine( _
                "Real number greater or equal to 0 and less than 1: {0}", _
                random.NextDouble())

            ' Fill an array of bytes with random numbers.
            Console.Write("Random bytes:")
            Dim values(9) As Byte
            random.NextBytes(values)
            For Each value As Byte In values
                Console.Write(" {0}", value)
            Next
            Console.WriteLine()

        End Sub

    End Module

End Namespace