Randomize a string

ahbenshaut

Well-known member
Joined
Oct 29, 2004
Messages
62
Location
Alaska
Programming Experience
5-10
Good Day!
I am trying to create a very simple program but I'm kinda lost. I have a simple form with a textbox, a button and a label. What I would to do is randomize the string that is entered into the textbox and display it in the label. I have never used the randomizer before and I'm having difficulty finding anything about randomizing user input.

Any help is greatly appreciated
 
Here is one example for you taking each character in first half of string and swaps with a random character in second half of string:
VB.NET:
Dim str As String = "some string to randomize"
Dim chars() As Char = str.ToCharArray
Dim tempchar As Char
Dim rnd As New Random
Dim rndint As Integer
For i As Integer = 0 To str.Length \ 2
  rndint = rnd.Next(str.Length \ 2, str.Length)
  tempchar = chars(i)
  chars(i) = chars(rndint)
  chars(rndint) = tempchar
Next
MsgBox(Convert.ToString(chars))
 
Excellent and I thank you for your help but it isn't totally random.:D I only had to click 4 times before I started to notice a pattern. Any other ideas?
 
Technically that algoritm produces a totally random swap of the input string, but be my guest keep on randomizing and swapping all you want until your satisfied. I must say that I don't get anything that even vaguely resembles the input string no matter how many times I run the code.
 
Back
Top