16,720
社区成员
发帖
与我相关
我的任务
分享Public Class Form1
Private r As New RandomForChar("D"c, "Q"c)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For i As Integer = 0 To 100
Console.WriteLine(r.Next)
Console.WriteLine(CType(r, RandomForInt).Next)
Next
End Sub
End Class
Public Class RandomForInt
Private Shared r As New Random(Now.Millisecond)
Private gFirst As Integer
Private gLast As Integer
Public Property First() As Integer
Get
Return gFirst
End Get
Private Set(ByVal value As Integer)
gFirst = value
End Set
End Property
Public Property Last() As Integer
Get
Return gLast
End Get
Private Set(ByVal value As Integer)
gLast = value
End Set
End Property
Sub New(ByVal first As Integer, ByVal last As Integer) '不作逻辑判断
Me.First = first
Me.Last = last
End Sub
Public Function [Next]() As Integer
Return r.Next(Me.First, Me.Last)
End Function
End Class
Public Class RandomForChar
Inherits RandomForInt
Sub New(ByVal first As Char, ByVal last As Char)
MyBase.New(Asc(first), Asc(last) + 1) '含Lst
End Sub
Public Shadows Function [Next]() As Char
Return Chr(MyBase.[Next])
End Function
End Class Random rnd = new Random();
int r=rnd.Next((int)((byte)'D'),(int)((byte)'Q'));
char c = (char)r;
Console.WriteLine(c);