获取两个标签之间的随机数 [英] Getting A Random Number Between Two Labels
本文介绍了获取两个标签之间的随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我有这个代码
Dim time As 新 Random()
Dim number As 整数 = Random(Label1,Label2)
但是我得到了
''随机''是一种类型一个不能用作表达式:(
任何建议请我如何对此进行排序。
解决方案
< blockquote>如果您阅读文档,您会发现以下内容:
http ://msdn.microsoft.com/en-us/library/system.random.aspx [ ^ ]
和代码:
Dim bytes1(9 9),bytes2(99)As Byte
Dim rnd1 As New Random()
Dim rnd2 As New Random()
rnd1.NextBytes(bytes1)
rnd2 .NextBytes(bytes2)
Console.WriteLine(First Series:)
for ctr As Integer = bytes1.GetLowerBound(0)to bytes1.GetUpperBound(0)
Console .Write({0,5},bytes1(ctr))
If(ctr + 1)Mod 10 = 0 Then Console.WriteLine()
Next
Console.WriteLine()
Console.WriteLine(Second Series:)
For ctr As Integer = bytes2.GetLowerBound(0)to bytes2.GetUpperBound(0)
Console.Write({0,5}} ,bytes2(ctr))
If(ctr + 1)Mod 10 = 0 Then Console.WriteLine()
Next
欺骗是使用 Random.Next
等。
Hi
I have this code
Dim time As New Random()
Dim number As Integer = Random(Label1, Label2)
However i get
''Random'' is a type an cannot be used as an expression :(
any suggestions please how i can sort this please.
解决方案
IF you read the documentation youll find something like this:
http://msdn.microsoft.com/en-us/library/system.random.aspx[^]
And the code:
Dim bytes1(99), bytes2(99) As Byte Dim rnd1 As New Random() Dim rnd2 As New Random() rnd1.NextBytes(bytes1) rnd2.NextBytes(bytes2) Console.WriteLine("First Series:") For ctr As Integer = bytes1.GetLowerBound(0) to bytes1.GetUpperBound(0) Console.Write("{0, 5}", bytes1(ctr)) If (ctr + 1) Mod 10 = 0 Then Console.WriteLine() Next Console.WriteLine() Console.WriteLine("Second Series:") For ctr As Integer = bytes2.GetLowerBound(0) to bytes2.GetUpperBound(0) Console.Write("{0, 5}", bytes2(ctr)) If (ctr + 1) Mod 10 = 0 Then Console.WriteLine() Next
Trick is to use theRandom.Next
etc.
这篇关于获取两个标签之间的随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文