Different numbers from 1 to 10

前端 未结 5 1086
太阳男子
太阳男子 2020-12-02 00:20

I want to generate 10 different numbers from a range of 0-9. the desired output may look like this, 9 0 8 6 5 3 2 4 1 7

Dim arraynum(9) As Integer
Dim crmd A         


        
5条回答
  •  庸人自扰
    2020-12-02 01:02

    This is the simplest but working code. Also there are no APIs!

    Dim a(1 To 10), tmp, count, isRepeated
    count = 1
    Randomize
    While count <= 10
        isRepeated = False
        tmp = Left(Rnd * 10, 1)
        For i = 1 To 10
            If tmp = a(i) Then isRepeated = True: Exit For
        Next
        If isRepeated = False Then a(count) = tmp: count = count + 1
    Wend
    YourLine = Join(a, "")
    

提交回复
热议问题