如何生成一个3位的随机数?谢谢!!!

解决方案 »

  1.   

    Private Sub Command1_Click()
    Randomize Timer
    Text1.Text = Round(Rnd * 1000)
    If Val(Text1.Text) < 100 Then  '保证是三位
    Call Command1_Click
    End If
    End Sub
      

  2.   

    0<=rnd<1
    Round是四舍五入这样rnd=0.9999的时候
    Round(Rnd * 1000)=Round(999.9)=1000标准写法是:
    为了生成某个范围内的随机整数,可使用以下公式:
    Int((upperbound - lowerbound + 1) * Rnd + lowerbound)而且3位的随机数应该是100~999
    对应公式就是:Int((999 - 100 + 1) * Rnd + 100)所以这个:
    Int(900 * Rnd + 100)
    才是3位的随机数
      

  3.   

    Dim A as Long
    Randomize Timer
    While A < 100
      A = Int(Rnd * 1000)
    Wend尽量用循环而不是递归