vb System.Random.Random类(方法)实例源码

下面列出了vb System.Random.Random 类(方法)源码代码实例,从而了解它的用法。

作者:VB.NET开发    项目:Syste   
' 导入命名空间
Imports System.Threading

Module RandomNumbers
   Public Sub Main()
      Dim rand1 As New Random()
      Dim rand2 As New Random()
      Thread.Sleep(2000)
      Dim rand3 As New Random()
      ShowRandomNumbers(rand1)
      ShowRandomNumbers(rand2)
      ShowRandomNumbers(rand3)
   End Sub
   
   Private Sub ShowRandomNumbers(rand As Random)
      Console.WriteLine()
      Dim values(4) As Byte
      rand.NextBytes(values)
      For Each value As Byte In values
         Console.Write("{0, 5}", value)
      Next      
      Console.WriteLine() 
   End Sub
End Module

作者:VB.NET开发    项目:Syste   
' Example of the Random class constructors and Random.NextDouble( ) 
' method.
Imports System.Threading

Module RandomObjectDemo

    ' Generate random numbers from the specified Random object.
    Sub RunIntNDoubleRandoms( randObj As Random )

        ' Generate the first six random integers.
        Dim j As Integer
        For j = 0 To 5
            Console.Write( " {0,10} ", randObj.Next( ) )
        Next j
        Console.WriteLine( )
            
        ' Generate the first six random doubles.
        For j = 0 To 5
            Console.Write( " {0:F8} ", randObj.NextDouble( ) )
        Next j
        Console.WriteLine( )
    End Sub 
        
    ' Create a Random object with the specified seed.
    Sub FixedSeedRandoms( seed As Integer )

        Console.WriteLine( vbCrLf & _
            "Random numbers from a Random object with " & _
            "seed = {0}:", seed )
        Dim fixRand As New Random( seed )
            
        RunIntNDoubleRandoms( fixRand )
    End Sub 
        
    ' Create a random object with a timer-generated seed.
    Sub AutoSeedRandoms( )

        ' Wait to allow the timer to advance.
        Thread.Sleep( 1 )
            
        Console.WriteLine( vbCrLf & _
            "Random numbers from a Random object " & _ 
            "with an auto-generated seed:" )
        Dim autoRand As New Random( )
            
        RunIntNDoubleRandoms( autoRand )
    End Sub 
        
    Sub Main( )
        Console.WriteLine( _
            "This example of the Random class constructors " & _
            "and Random.NextDouble( ) " & vbCrLf & _
            "generates the following output." & vbCrLf )
        Console.WriteLine( "Create Random " & _
            "objects, and then generate and display six " & _
            "integers and " & vbCrLf & "six doubles from each." )
            
        FixedSeedRandoms( 123 )
        FixedSeedRandoms( 123 )
            
        FixedSeedRandoms( 456 )
        FixedSeedRandoms( 456 )
            
        AutoSeedRandoms( )
        AutoSeedRandoms( )
        AutoSeedRandoms( )
    End Sub
End Module 

' This example of the Random class constructors and Random.NextDouble( )

作者:VB.NET开发    项目:Syste   
' 导入命名空间
Imports System.Threading

Module RandomNumbers
   Public Sub Main()
      Dim rand1 As New Random(CInt(Date.Now.Ticks And &h0000FFFF))
      Dim rand2 As New Random(CInt(Date.Now.Ticks And &h0000FFFF))
      Thread.Sleep(20)
      Dim rand3 As New Random(CInt(Date.Now.Ticks And &h0000FFFF))
      ShowRandomNumbers(rand1)
      ShowRandomNumbers(rand2)
      ShowRandomNumbers(rand3)
   End Sub
   
   Private Sub ShowRandomNumbers(rand As Random)
      Console.WriteLine()
      Dim values(4) As Byte
      rand.NextBytes(values)
      For Each value As Byte In values
         Console.Write("{0, 5}", value)
      Next      
      Console.WriteLine() 
   End Sub
End Module


问题


面经


文章

微信
公众号

扫码关注公众号