Results 1 to 6 of 6

Thread: random number

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Posts
    20

    Post

    ok. i got a command button and a label. i click the command button. and it will pick a random number from 1 to 1000. and it will change label 1 caption to the number.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Code:
    Private Sub Command1_Click()
        Randomize Timer
        Label1 = Int(Rnd * 999) + 1
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  3. #3
    Guest

    Post

    Function RandRange(byval Lower as Double, Byval Upper as Double, Optional MyInt as Boolean = True)

    Randomize

    Select Case MyInt
    Case Is = True
    RandRange = Int((rnd * (Upper - Lower)) + Lower)
    Case Is = False
    RandRange = (rnd * (Upper - Lower)) + Lower
    End Select
    End Function


    the above is a function that i wrote for a fractal app.

    Syntax is:

    RandRange(Lower as double, Upper as double, MyInt as Boolean)

    It picks a random number between LOWER and UPPER, if you specify MyInt as false, then it will return a nuber with a decimal: ie. 111343275882.6774439, or something, the default is true (always a whole number returned).

    hope this is usefull to someone

    ------------------

    Wossname,
    Email me: [email protected]

  4. #4
    Hyperactive Member
    Join Date
    Jul 1999
    Location
    NY, USA
    Posts
    270

    Post

    Aaron, what would happen if you didn't put a Randomize Timer in it?

    ------------------
    Tom Young, 14 Year Old
    [email protected]
    ICQ: 15743470 Add Me ICQ Me
    AIM: TomY10
    PERL, JavaScript and VB Programmer

  5. #5
    Member
    Join Date
    Feb 1999
    Location
    ,Mo,USA
    Posts
    36

    Post

    hey- im not Aaron, but i can answer your question Compwiz...If you didnt put in randomize timer it would pick the same "random" number each time.Randomize Timer sets the "seed" value of the randomizer based on the time of day,so it will always be different.Hope to have helped,

    Thnx for your time,
    CarlosTheJackal

  6. #6
    Hyperactive Member
    Join Date
    Jul 1999
    Location
    NY, USA
    Posts
    270

    Post

    Kewl, thanx. I didn't mean to address the question to just Aaron, but he made the code so... thanx!

    [This message has been edited by Compwiz (edited 11-28-1999).]

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