Results 1 to 3 of 3

Thread: Random Number Generation

  1. #1
    Pryzm
    Guest

    Question Random Number Generation

    I am new to VB and was wondering if anyone knows how to generate random numbers? Like 1 - 100 or 4D6 were each die is a random accurence then the numbers are added together for an answer.

    I thank you for the help.

    MLC

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Private Sub Command1_Click()
    Dim i As Integer, iNum As Integer, iTotal As Integer
    Randomize
    For i = 1 To 6
       iNum = (Rnd * 100) + 1 'number from 1 to 100
       iTotal = iTotal + iNum
    Next i
      MsgBox iTotal
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Megatron
    Guest
    If you want whole numbers (no decimals) then round it off with Int().
    VB Code:
    1. iNum = Int(Rnd * 101)

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