Here is the code, fairly self explanatory
Public Class Form1
' declare variables
Dim target As String = ""
Dim source As String = ""
Dim list As New ArrayList
Dim loc As Integer = 0
' randomize method
Private Function rnd(ByVal s As String)
' declare variables
Dim rndStr As String = ""
Dim random As New Random()
' for each character in the string
For Each i As Char In s
' add it to arraylist
list.Add(i)
Next
' for each character in list
For Each i As Char In list
' get random position in the list
Dim t As Integer = random.Next(list.Count)
' concatenate the character to a string
rndStr += list(t)
' set label text to string
Label1.Text = rndStr
Me.Refresh()
Next
Return rndStr
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' declare variables and assign values
target = TextBox1.Text
source = rnd(target)
Dim sLoc As Integer = 0
Dim tmp As String = ""
Dim i As Integer
' fixing loop
While Not source = target
' if it's the last char in the list
If loc = list.Count Then
' go back to beginning
loc = 0
End If
' for each char in randomized string
For Each c As Char In source
' if the char is not equal to the char in the list location
If Not c = list(loc) Then
' get a random char in the list
Dim random As New Random()
i = random.Next(list.Count)
' assign the char from the list to the current char
c = list(i)
' concatenate on the char
source += c
' remove the char at the location
source = source.Remove(loc, 1)
Else
' TODO: Remove corresponding list item
End If
' set label text to source
Label1.Text = source
Me.Refresh()
' increment location in list
loc += 1
Next
End While
End Sub
End Class
This is the download, I forgot to attach it.
Attached File(s)
-
Evolutionary Strings.zip (72.87K)
Number of downloads: 15

New Topic/Question
Reply



MultiQuote




|