how can randomize a word in a textbox, for example if the word is cat it would randomize the letters to like cta or tac or something?
Printable View
how can randomize a word in a textbox, for example if the word is cat it would randomize the letters to like cta or tac or something?
i would store the letters in an arraylist, then in a loop, call random numbers which pick from the arraylist and remove each lette rone by one.
VB Code:
dim chr() As Char = "somewhere".ToCharArray dim Letters As New Arraylist For each c as char in chr Letters.Add(c) Next
then when you make the word, perform a loop, use randomize to pick a random number between 0 and (letters.count-1), and dont forget to .removeAt the index picked, so that it is not picked again.
Hope i explained well enough
i'm sorry but can you explain the random solution again, i don't understand.
VB Code:
Dim newWord as string dim r as random dim i as integer Do While Letters.Count > 0 i = r.Next(Letters.Count-1) newWord &= Letters(i) Letters.RemoveAt(i) Loop
that loops, picking randomly from the array of letters until no more letters are left to choose from
VB Code:
Dim myArrayList As New ArrayList myArrayList.AddRange(myString.ToCharArray())
to add the items to a listbox would i got listbox1.add.items(newword) right before the loop?
right after the loop, that loop constructs newWord