Skip to content

Instantly share code, notes, and snippets.

@jda0
Created December 12, 2013 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jda0/7932018 to your computer and use it in GitHub Desktop.
Save jda0/7932018 to your computer and use it in GitHub Desktop.
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