Created
December 12, 2013 17:35
-
-
Save jda0/7932018 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class Form1 | |
' Form controls: Label Label1, TextBox TxtLimit, Button BtnExe, ListBox LstItems, Label LblInfo | |
Dim r As Random | |
Dim l, s, t As Integer | |
Dim z As Date | |
Private Sub BtnExe_Click(sender As System.Object, e As System.EventArgs) Handles BtnExe.Click | |
z = Date.UtcNow() | |
LblInfo.Text = "Running..." | |
Try | |
t = 0 | |
l = CInt(TxtLimit.Text) | |
LstItems.Items.Clear() | |
For i As Integer = 1 To l | |
s = r.Next(2) | |
LstItems.Items.Add(GetCoinState(s)) | |
t += s | |
Next | |
Catch ex As Exception | |
LblInfo.Text = "Error: " + ex.Message | |
Exit Sub | |
End Try | |
LblInfo.Text = "Finished in " + CStr((Date.UtcNow - z).TotalMilliseconds Or 0) + "ms - " + CStr(l - t) + " Heads and " + CStr(t) + " Tails" | |
End Sub | |
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load | |
r = New Random() | |
End Sub | |
Function GetCoinState(_state As Integer) | |
If _state = 0 Then | |
Return "Heads" | |
Else | |
Return "Tails" | |
End If | |
End Function | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment