且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何随机选择三个字符串之一?

更新时间:2023-01-19 21:32:44

我建议您为此使用 ListOf 字符串.您可以编写如下代码;

I suggest you to use ListOf string instead for this. you can code like the following;

    Dim listofStrings As New List(Of String) ' Declaration of list of strings
    listofStrings.Add("qwertyuiopasdfghjklzxcvbnm") 'assign values to the list
    listofStrings.Add("MNBVCXZLKJHGFDSAPOIUYTREWQ")
    listofStrings.Add("1234567890")
    Dim rnd As New Random
    Dim randomString As String = listofStrings.Item(rnd.Next(0, 3))'select random string from the list

它将生成 0 到 2 之间的随机数,因此它将帮助您根据随机数引用的索引从字符串列表中选择随机字符串

it will generate random numbers between 0 and 2 hence it will help you to select random string from the list of strings based on index referenced by the random number