Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,456
    Thanks
    15
    Thanked 0 Times in 0 Posts

    random 7 digit number

    i'm using
    Randomize ' Initialize random-number generator.
    rnumber= Int((9999999 * Rnd) + 1000000)

    to generate a random 7 digit number -- but sometimes it is not 7 digits but 8

    why? and how can I get a random 7 digit number

  • #2
    Regular Coder PremiumBlend's Avatar
    Join Date
    Apr 2006
    Location
    Marion, Iowa
    Posts
    201
    Thanks
    0
    Thanked 13 Times in 13 Posts
    What is happening is you're first creating a random number using this:

    Code:
    (9999999 * Rnd)
    which creates a number between 0 and 9999999, if the number generated is over 9000000, by adding 1000000 to it, it will be an 8 digit number.

    trying this code:

    Code:
    Randomize ' Initialize random-number generator.
    rnumber= Int((8999999 * Rnd) + 1000000)
    My Website: DumpsterDoggy

  • #3
    SSJ
    SSJ is offline
    Regular Coder
    Join Date
    Mar 2007
    Posts
    230
    Thanks
    0
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by PremiumBlend View Post
    What is happening is you're first creating a random number using this:

    Code:
    (9999999 * Rnd)
    which creates a number between 0 and 9999999, if the number generated is over 9000000, by adding 1000000 to it, it will be an 8 digit number.

    trying this code:

    Code:
    Randomize ' Initialize random-number generator.
    rnumber= Int((8999999 * Rnd) + 1000000)
    Really Interesting...

  • #4
    Regular Coder PremiumBlend's Avatar
    Join Date
    Apr 2006
    Location
    Marion, Iowa
    Posts
    201
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Really Interesting...
    I don't follow.
    My Website: DumpsterDoggy


  •  

    Posting Permissions

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