Results 1 to 5 of 5

Thread: Random

  1. #1

    Thread Starter
    Member
    Join Date
    May 2004
    Location
    Where i am
    Posts
    38

    Random

    Im trying to do something but it requires the use of random numbers and i can make random numbers but i want them in a certain range eg 1-10

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    my_number = (rnd() * (max_val - min_val + 1)) + min_val

    in this particular case:
    my_number = (Rnd() * (10 - 1)) + 1

  3. #3
    Addicted Member
    Join Date
    Aug 2002
    Location
    Luton, UK
    Posts
    178
    ERROR!!
    my_number = (Rnd() * (10 - 1)) + 1
    This only gives random numbers 1 to 9.

    The correct formula is :-
    Code:
    MyNumber = Int(Rnd() * 10) + 1
    Regards
    BrianB
    -------------------------------

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    oops.. I forgot to carry across the +1!

    it should have been :
    my_number = (Rnd() * (10 - 1 + 1)) + 1

    (which is the same as you said!)

  5. #5

    Thread Starter
    Member
    Join Date
    May 2004
    Location
    Where i am
    Posts
    38

    Thanx

    Thanx very much

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