包含vb.netrand的词条
vb.net 随机出数字,但要求包含特定数字如何做?
下面是你需要的,经过三次随机,可以看一下,直接调用函数返回一个字符就是你要的,看不懂再追问哈
定南网站建设公司成都创新互联,定南网站设计制作,有大型网站制作公司丰富经验。已为定南近千家提供企业网站建设服务。企业网站搭建\外贸网站建设要多少钱,请找那个售后服务好的定南做网站的公司定做!
Structure jiqi
Dim num As Integer
Dim num2 As Integer
End Structure
Public Function chansheng() As String
Dim str As String = ""
Dim n As Integer = 0
Dim p68 As Integer
Randomize()
p68 = Int(Rnd() * 2) + 1
Dim a(10), b(8) As Integer
For i = 1 To 6
b(i) = i - 1
Next
b(7) = 7
b(8) = 9
For i = 1 To 6
Randomize()
a(i) = b(Int(Rnd() * 8) + 1)
Next
If p68 = 1 Then
For i = 7 To 10
a(i) = 6
Next
ElseIf p68 = 2 Then
For i = 7 To 10
a(i) = 8
Next
End If
Dim c(10) As Integer
Dim temp As jiqi
Dim pi(10) As jiqi
For i = 1 To 10
pi(i).num = a(i)
pi(i).num2 = Int(Rnd() * 1000) + 10
Next
For i = 1 To 10
For j = 1 To 10 - i
If pi(j).num2 pi(j + 1).num2 Then
temp = pi(j + 1)
pi(j + 1) = pi(j)
pi(j) = temp
End If
Next j
Next i
For i = 1 To 10
str = str pi(i).num
Next
Return str
End Function
vb.net产生随机数
方法名称:next();功能描述:返回一个0~2147483647之间的整数
方法名称:next(i);功能描述:返回一个0~i之间的整数
方法名称:next(i,j);功能描述:返回一个i~j之间的整数
方法名称:Nextdouble();功能描述:返回一个0~1之间的随机小数
================
使用方法:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim rand = New System.Random()
MsgBox(rand.next().ToString())
End Sub
==========================
产生N个不同数的话,我给你个我写的VB的代码,你稍微改下:
产生0-10的数:
Private Sub Command1_Click()
Randomize
Dim a(10) As Long
n = 10
For i = 0 To n
a(i) = Int(Rnd() * (n + 1))
For j = 0 To i - 1
If a(i) = a(j) Then
i = i - 1
Exit For
End If
Next
Next
For i = 0 To n
Print a(i)
Next
End Sub
如何用VB.NET生成一个随机字符串
用法 RndString(xx) xx为随机数字长度
比如12位长度的随机字符串 则为 RndString(12)
字符串包含数字和大小写字母,函数如下:
Function RndString(ByVal l As Integer) As String
Randomize()
Dim R, i As Integer
Dim S As Char
Dim returnStr As String
returnStr = ""
'a-z 的ASCII码是:97-122
'A-Z 的ASCII码是:65-90
'0-9 的ASCII码是:48-57
For i = 1 To l
R = Int(Rnd() * 62) '随机生成的字符有大小写字母和数字,共有26个
If R 10 Then '如果小于10,则是数字 数字的ASCII是48-57 对应 随机数字 0-9 所以要将随机数字加48
S = Chr(R + 48) 'Chr 是将把数字按Ascii码转换为对应的字符
ElseIf R 36 Then '如果小于36,则是大写字母 大写字母的ASCII是65-90 对应 随机数字10-35 所以要将随机数字加55
S = Chr(R + 55)
Else '如果大于36,则是小写字母 小写字母的ASCII是97-122 对应 随机数字36-62 所以要将随机数字加61
S = Chr(R + 61)
End If
returnStr = returnStr + S
Next
RndString = returnStr
End Function
网站标题:包含vb.netrand的词条
网站地址:http://cdiso.cn/article/doedhhe.html