产生十个(0-10)内的不同随机整数
要最快的,
最好的算法,,
要调试通过的,给出原码~~
50分就是你的了~~~~~~~~~~~~~~~~~~~~!!!

解决方案 »

  1.   

    Rnd(10)不就行了?
    怎么个叫最好?
      

  2.   

    不能用rnd(10)那样你每次得到的随机数是一样的,并不是真正的随机,其实,rnd()是系统早就有预谋的数字.
    Randomize
    Print Int(10 * Rnd() + 1)
    每次得到随机前要randomize一下,初始化!
      

  3.   

    Private Sub Command1_Click()
        Randomize
        For i = 1 To 10
            Print Int(10 * Rnd())
        Next
    End Sub
      

  4.   

    Private Sub Command1_Click()
        Randomize(now)
        For i = 1 To 10
            Print Int(10 * Rnd())
        Next
    End Sub
      

  5.   


    Private Sub Riffle(ArrItems() As Integer)
        Dim i   As Long
        Dim j   As Long
        Dim nLo As Integer
        Dim nHi As Integer
        Dim n   As Integer
        nLo = LBound(ArrItems)
        nHi = UBound(ArrItems)
        Randomize
        For i = nLo To nHi
            j = Rnd * (nHi - nLo) + nLo
            n = ArrItems(i)
            ArrItems(i) = ArrItems(j)
            ArrItems(j) = n
        Next
    End SubPrivate Sub PrintItems(ArrItems() As Integer)
        Dim i As Integer
        Debug.Print String$(40, "-")
        For i = LBound(ArrItems) To UBound(ArrItems)
            Debug.Print ArrItems(i)
        Next
        Debug.Print String$(40, "-")
    End SubPrivate Sub Command1_Click()
        Dim ArrItems(9) As Integer
        Dim i           As Integer
        For i = 0 To 9
            ArrItems(i) = i
        Next
        PrintItems ArrItems()
        Riffle ArrItems
        PrintItems ArrItems()
    End Sub
      

  6.   

    lihonggen0(李洪根,用.NET,标准答案来了)    bobob(bobob)   程序没有10Fearfulness(谁都知道我最拽)     你的程序没有0 楼主要0-10 之间的数啊!Private Sub Form_Click()
      
      Cls
      Randomize
        
      For i = 1 To 10
        Print Int(11 * Rnd())
      NextEnd Sub
      

  7.   

    "产生十个(0-10)内的不同随机整数"
    我看上面的大哥们好象没有看仔细。
    其实用一个标志就可以了
    Private Sub Command1_Click()
    Static Flag(0 To 10) As String
    Dim Isok As Boolean
    Dim Num As Integer
      Do
        Isok = True
        For i = 1 To 10
            If Flag(i) <> "Yes" Then
                 Isok = False
                 Exit For
            End If
        Next i
        If Isok = False Then
            Randomize
            Num = Int(11 * Rnd())
            If Flag(Num) <> "Yes" Then
                 Debug.Print Num
                 Flag(Num) = "Yes"
            End If
        Else
            Exit Do
        End If
      Loop
    End Sub
      

  8.   

    Private Sub Command1_Click()
        Randomize
        For i = 1 To 10
            Print Int(10 * Rnd())
        Next
    End Sub
      

  9.   

    Private Sub Command1_Click()
        Randomize
        For i = 1 To 10
            Print Int(11 * Rnd())
        Next
    End Sub这样不就可以了吗?  还用其它的方法吗?
      

  10.   

    没想到一个平时觉得简单的问题都要这的讨论,不过还是学了不少。
    liu584() Intelement(智能元素)两位仁兄的能够产生不重复的数
      

  11.   

    同意liu584()的说法,但其程序要修正一下,前面要加上:
    For i = 0 To 10
        Flag(i) = "no"
    Next
    不然,执行一次之后,就会因Flag(i)全部被置为"yes",而出现问题。
      

  12.   

    建议使用数组,Intelement(智能元素)写的够详细的了
      

  13.   

    我懒得写代码了,因为我不是在我家里的计算机上上网的。我编程序时也用到这么个功能,我这么做的:先定义数组 P(),从 P(1) = 1 到 p(N) = N 依次填进去,然后让它随机生成 1 - N 之间两个不同的数 i、j,再将 P(i) 和 P(j) 的值交换,如此循环多次(我是让它循环 Sqr(N) 次,如果 N < 10,则循环 10 次)。