【发布时间】:2014-10-23 07:05:33
【问题描述】:
我想创建一个骰子滚轮,以便用户可以选择骰子上的多个面,它会随机响应,我当前的代码总是抛出相同的数字。
Sub rollDie(ByVal sides As Integer)
Dim rand As Single = Rnd()
For cnt As Integer = 1 To sides
If rand < cnt / sides Then
diceRoll = cnt
Exit For
End If
Next
Console.WriteLine("You rolled a {0} sided die which landed on {1}", sides, diceRoll)
End Sub
【问题讨论】:
-
Rnd 是一个遗留函数。有关首选方法,请参阅 MattWilko 答案。