Support Forums

Full Version: [Snippet] Random pick from list (Range)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        MsgBox(getrandom)
    End Sub

    Shared Function getrandom() As String
        Dim Random As New Random
        Dim order As New List(Of String)
        order.AddRange(New String() {"First", "Second", "Third", "Fourth", "Fifth", _
                                     "Sixth", "Seventh", "Eight", "Ninth", "Tenth", })

        Dim itemnumber As Integer = Random.Next(order.Count)
        Return order(itemnumber)
    End Function

Every time you click on msgbox it random pick the result from list/range.