Results 1 to 3 of 3

Thread: Randomize (2K3)

  1. #1
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Randomize (2K3)

    This bit is not clear to me so if someone can explain this in words of one syllable I would be grateful.

    I am plotting a XY Scatter graph of 2 columns of random numbers with the seed 1. When I plot the graphs I get a seemingly random chart however if I place randomize in the code I get a striated chart...what is going on there?
    Jerry

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Randomize (2K3)

    From the help for Randomize:
    <hr>Randomize uses number to initialize the Rnd function's random-number generator, giving it a new seed value. If you omit number, the value returned by the system timer is used as the new seed value.<hr>
    If you use Randomize within a loop that executes very fast, the values of the system timer will be identical or almost identical, this causes the pattern. You should use Randomize only once, at the beginning of the procedure.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Randomize (2K3)

    Got you, I was playing with this while waiting for a reply and took Randomize out of the loop and it reverted to a random pattern again..thanks.

    Any body interested here is the code:

    <pre>Sub Fract()
    Dim i As Integer
    Dim rndY As Single
    Dim rndX As Single

    Randomize

    For i = 1 To 8000

    rndY = Rnd(1)
    rndX = Rnd(1)

    Cells(i, 1) = rndY
    Cells(i, 2) = rndX

    Next i


    End Sub
    </pre>

    Jerry

Posting Permissions

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