Skip to content

Instantly share code, notes, and snippets.

@tkshnwesper
Last active September 21, 2016 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkshnwesper/b6775bc68d918db9f93b978779bf32ff to your computer and use it in GitHub Desktop.
Save tkshnwesper/b6775bc68d918db9f93b978779bf32ff to your computer and use it in GitHub Desktop.
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