Skip to content

Instantly share code, notes, and snippets.

@cipepser
Created December 29, 2016 07:55
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 cipepser/72bf7cadaab3f3219dab0349223925ad to your computer and use it in GitHub Desktop.
Save cipepser/72bf7cadaab3f3219dab0349223925ad to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"strings"
"math/rand"
"time"
)
func FisherYatesShuffle (s string) string {
r := rand.New(rand.NewSource(time.Now().UnixNano() ))
t := []rune(s)
var j int
for i := 0; i < len(t) - 1; i++ {
j = r.Intn(len(t) - 1 - i)
t[len(t) - 1 - i], t[j] = t[j], t[len(t) - 1 - i]
}
return string(t)
}
func main() {
var s string = "I couldn't believe that I could actually understand what I was reading : the phenomenal power of the human mind ."
var u string
var v_tmp []rune
for _, v := range strings.Split(s, " ") {
if len(v) > 4 {
v_tmp = []rune(v)
v = string(v_tmp[0])
v += FisherYatesShuffle(string(v_tmp[1:len(v_tmp)-1]))
v += string(v_tmp[len(v_tmp)-1])
}
u += v + " "
}
u = u[0:len(u)-1] // remove last blank
fmt.Println(u)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment