How can I randomly select one of three strings?

后端 未结 2 1122
你的背包
你的背包 2021-01-29 09:10

I have to create a password and I believe that I can do it, however I am stumped at the very beginning. I have 3 strings of characters, I would like to randomly select one of th

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-29 09:38

    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
    

    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

提交回复
热议问题