Results 1 to 4 of 4

Thread: [RESOLVED] Question about New Random

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2013
    Posts
    488

    Resolved [RESOLVED] Question about New Random

    Hello
    I know how to seed the random number generator, so as to get the same sequence every time.
    This is what I would like to know.
    Code:
    Option Explicit On
    Option Strict On
    Imports System.Math
    
    Public Class Form1
           Dim rng As New Random
        Private Sub shuffleCards()
            Dim rng As New Random
        end sub
    I want to know what value was used so I can set the seed to it and repeat the random sequence, if needed or just continue on. By the way I am using this to test and debug a program.
    When I try to find it out I get error messages.(Error 1 Value of type 'System.Random' cannot be converted to 'Decimal'.)
    Thanks in advance
    George

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: Question about New Random

    The Random seed, unless specified, is the PC TickCount at the time the Random Object is created

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,764

    Re: Question about New Random

    Code:
    Public Class Form1
    
        Private Shared prng As New Random(1) 'remove the 1 for normal operation
    
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Debug.WriteLine(prng.Next)
        End Sub
    End Class
    This shows what paul said.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2013
    Posts
    488

    Re: Question about New Random

    Thank you both.
    george

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width