Results 1 to 3 of 3

Thread: Random number generator

  1. #1
    Guest

    Post

    How would create a random number generator between the limits of 1 and 20 for a multiple choice test??

  2. #2
    Lively Member
    Join Date
    Dec 1999
    Posts
    106

    Post

    See the VB help on the Rnd function

    Private Function RandomNum() As Integer
    RandomNum = Int((20 - 1 + 1) * Rnd + 1)
    End Function

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Add Randomize to hayessj's soultion or your set of random numbers will repeat each time you run the program.

    Private Function RandomNum() As Integer
    Randomize
    RandomNum = Int((20 - 1 + 1) * Rnd + 1)
    End Function

    ------------------
    Marty

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