Results 1 to 2 of 2

Thread: Random number

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    1

    Random number

    This is the first time i'm using VB and was wondering how i can randomly generate numbers from 1-5. is it just:

    dim x as integer=Rnd(4)+1

    ??

    also, do i import anything for the Rnd method to work? Or create some sort of function?

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Random number

    Welcome to the forums.

    Recommend adding this line in your form's load event: Randomize Timer
    That call will use the system timer value (changes each millisecond) to seed the random number generator. You can seed the generator with any number you choose

    A formula to retrieve a random number in a range of 1 to Max is
    X = Int(Rnd * [max number]) + 1
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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