Skip to content

Instantly share code, notes, and snippets.

@tkshnwesper tkshnwesper/strshuffle.go
Last active Sep 21, 2016

Embed
What would you like to do?
String Shuffle in Go
// StrShuffle shuffles a string that is passed to it
func StrShuffle(str string) string {
n := 25 + rand.Intn(25)
var runes []rune
for _, runeval := range str {
runes = append(runes, runeval)
}
var shuffle = func() bool {
if rand.Intn(2) == 1 {
return true
}
return false
}
var repeat = func() {
for i := 0; i < len(runes) - 1; i++ {
if shuffle() {
temp := runes[i]
runes[i] = runes[i + 1]
runes[i + 1] = temp
}
}
n--
}
for n > 0 {
repeat()
}
return string(runes)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.