Results 1 to 3 of 3

Thread: [RESOLVED] My random numbers ain't!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Location
    Townsville, Qld, Australia
    Posts
    135

    Resolved [RESOLVED] My random numbers ain't!

    I have a selection of arrays, and I want to pick a single item out of them at random. The problem is that when I run my code the sequence in which my "random" selections appear is the same. This is the code I am using:

    Code:
    Sub RandomTexts()
    For i = 1 To 7
    destin1(i) = Sheets("mutable 1").Cells(2 + i, 2)
    Next i
    strDestin1 = destin1(Int(7 * Rnd) + 1)
    End Sub
    I hope there is a smiple solution. Thanks for your help.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: My random numbers ain't!

    If you look at the help for Rnd you will see that behaviour is expected, and the way to fix it is easy... just run the following line of code once (perhaps in the Workbook_Open event):
    Code:
    Randomize

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Location
    Townsville, Qld, Australia
    Posts
    135

    Re: My random numbers ain't!

    Thanks for that. Problem solved. Project to subtly subvert a middle class Christmas custom is back on track!!

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