Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
成都创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站设计、网站建设、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的临邑网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
Dim i, j
j = GetRndNotRepeat(1, 10, 10)
If j(0) Then
For i = 1 To 10
MsgBox(j(i))
Next
End If
End Sub
Public Function GetRndNotRepeat(ByVal NumMin As Integer, ByVal NumMax As Integer, ByVal n As Integer)
'编制:xsfhlzh
'功能:取NumMin到NumMax间的n个随机整数
'说明:取数标志数组是Byte,每一位表示NumMin到NumMax间某个数的状态
Dim arr() As Integer
If n NumMax - NumMin + 1 Then
ReDim arr(0)
arr(0) = 0
Return arr
Else
ReDim arr(n)
Dim m As Integer
Dim b() As Byte
m = Int((NumMax - NumMin) / 8)
ReDim b(m)
'取数标志
Dim i
Dim x, y, z As Integer
Randomize()
arr(0) = 1
For i = 1 To n
Do
'找到x的位置,y表示x在数组的第几个字节,z表示x在该字节的第几位
x = Int(Rnd() * (NumMax - NumMin + 1)) + NumMin
y = x - NumMin
z = 2 ^ (y Mod 8)
y = y \ 8
Loop While b(y) And z
b(y) = b(y) Or z
arr(i) = x
'找到未取的数,并放入数组,设置标志位
Next i
End If
Return arr
End Function
'项目:VB中产生在一定正整数范围内的不重复的随机数'作者:qq15495835Private Sub Command1_Click() Max = 100 '随机数上限值 Min = 1 '随机数下限值 Amount = 10 '产生号码数量(数量值应小于随机数上限值-随机数下限值)否则会产生死循环 ReDim a(Amount) Randomize For i = 0 To Amount a(i) = Int((Max - Min + 1) * Rnd + Min) For j = 0 To i If i j And a(i) = a(j) Then i = i - 1 Next Next Text1 = Join(a, vbCrLf)End Sub'请采纳参考!谢谢!
Imports System.Linq
Module Module1
Sub Main()
Dim nums() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Dim r As New Random
Dim result As Integer() = nums.OrderBy(Function(x)
Return r.Next
End Function).Take(6).ToArray
'检验
For Each n In result
Console.WriteLine(n)
Next
Console.ReadLine()
End Sub
End Module
其实用Environment.TickCount就可以了,函数获取系统启动后经过的毫秒数
因为时间不重复,所以如果间隔1秒永不重复且随机