随机字母问题?

拿铁装咖啡 2008-04-08 09:26:29
怎样编写产生D到Q之间的随机字母啊?
...全文
131 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuhongyao3 2008-04-08
  • 打赏
  • 举报
回复
学习了。
水如烟 2008-04-08
  • 打赏
  • 举报
回复
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
jinjazz 2008-04-08
  • 打赏
  • 举报
回复
 Random rnd = new Random();
int r=rnd.Next((int)((byte)'D'),(int)((byte)'Q'));
char c = (char)r;
Console.WriteLine(c);

16,720

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧