Results 1 to 3 of 3

Thread: Generating Random Number

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    3

    Question

    Anyone know any code to make VB generate a random number between 1-100, 1-20, 1-10, and 1-6? For anyone who plays AD&D, i'm making a Magical Item Generating program.

  2. #2
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    alter this to your needs
    Code:
    'generates a random # between 6 and 1
    Randomize
    RandomInteger = Int((Rnd * 6) + 1)
    'code from dennis

  3. #3
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    You've come to the right man ;-)

    I have a function for this at home.. but I can give you a quick and dirty cut of it now out of my head.

    Code:
    Function DiceRoll(NumDice As Integer, DieType As Integer) as Integer
      Dim iDieNum as Integer
    
      Randomize
    
      DiceRoll = 0
      For iDieNum = 1 to NumDice
        DiceRoll = DiceRoll + Int(Rnd * DieType) + 1
      Next iDieNum
    End Function
    d100 = DiceRoll(1,100)
    2d20 = DiceRoll(2,20)
    3d10+3 = DiceRoll(3,10) + 3

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