Results 1 to 6 of 6

Thread: [2005] Random number from 1 to 10

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2005
    Posts
    331

    [2005] Random number from 1 to 10

    How do I make a random number that displays... random numbers... from 1 to 10?
    So I click a button and it says 8
    I click it again and it says 3

    Get it? How do I do that?
    Katya Chehova is best!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Random number from 1 to 10

    Create an instance of the Random class and use its Next method. Make sure you read the documentation first. Also make sure you only create one object and reuse it rather than creating a new object each time.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Addicted Member phenom's Avatar
    Join Date
    Apr 2006
    Location
    UAE
    Posts
    233

    Re: [2005] Random number from 1 to 10

    Hi 3dmaker,
    try this:
    VB Code:
    1. Dim RND As New Random
    2. MessageBox.Show(RND.Next(0, 10))

    Hope this helps...

    Regards,
    =======================================
    If I helped you, Kindly Rate my post. Thanks
    -----------
    PHENOM

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Random number from 1 to 10

    As I suggested, it is a good idea to read the doco. It should be Next(1, 11) to get a number from 1 to 10.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2005
    Posts
    331

    Re: [2005] Random number from 1 to 10

    Ahaa...
    I see! Thank you guys.
    I will take a look at the documentation right now.
    Katya Chehova is best!

  6. #6
    Addicted Member phenom's Avatar
    Join Date
    Apr 2006
    Location
    UAE
    Posts
    233

    Re: [2005] Random number from 1 to 10

    Quote Originally Posted by jmcilhinney
    As I suggested, it is a good idea to read the doco. It should be Next(1, 11) to get a number from 1 to 10.
    Thanks for the correction jmcilhinney

    3dmaker as jmcilhinney said try to have a look @ the documentation, if you got what you want don't forget to resolve your thread
    Regards,
    =======================================
    If I helped you, Kindly Rate my post. Thanks
    -----------
    PHENOM

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