Results 1 to 6 of 6

Thread: Random #

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Posts
    4

    Post

    How do you generate a random number?

    ------------------
    //R//A//Y//
    ///L///I///

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    Post

    You can use the Rnd function to get random numbers (from a lookup table) and randomize them by time with the Randomize function:

    -
    'This will return the same number every time you restart the project
    Print 10 * Rnd


    'And this will print true "random" numbers
    Randomize
    Print 10 * Rnd
    -

    ------------------
    [email protected]
    ...
    Every program can be reduced to one instruction which doesn't work.


  3. #3
    Lively Member *Super Sniper*'s Avatar
    Join Date
    Jan 2000
    Location
    Portland, OR
    Posts
    81

    Post

    Here is how to make a true interger random number:

    randomize
    int((UBOUND - LBOUND + 1) * rnd + LBOUND)

    ------------------
    Website

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Posts
    4

    Post

    Thanks!
    1 thing I don't get is that what does the UBOUND and LBOUND mean?
    When I try to interpret it, it says that a () is missing.

    ------------------
    //R//A//Y//
    ///L///I///

  5. #5
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    Post

    Well, I didn't try but I don't think that the code'll work. With UBound and LBound you can get the upper and lower count of an array. Example:

    -
    Dim Temp(10) as Long

    Caption = UBound(Temp) 'Returns 10
    Caption = LBound(Temp) 'Returns 0
    -

    ------------------
    [email protected]
    ...
    Every program can be reduced to one instruction which doesn't work.


  6. #6
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    Post

    I think what he wanted to show ya is how to generate a random number between some range.

    Here's a function you can copy:

    -
    Function Rand(LVal as Long, UVal as Long)
    Randomize
    Rand = (UVal - LVal + 1) * Rnd + LVal
    End Function
    -

    Now you can call the function and get a random number between UVal and LVal.

    ------------------
    [email protected]
    ...
    Every program can be reduced to one instruction which doesn't work.


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