Skip to content

Instantly share code, notes, and snippets.

@selfup
Created September 14, 2018 04:22
Show Gist options
  • Save selfup/e6dfc0191017ea9ffbb6e5959710c4f2 to your computer and use it in GitHub Desktop.
Save selfup/e6dfc0191017ea9ffbb6e5959710c4f2 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math/rand"
"strings"
"sync"
)
func main() {
str := "REALLY LONG STRING"
strLength := len(str)
var result []string
var mutex = &sync.Mutex{}
var wg sync.WaitGroup
wg.Add(strLength)
for i := 0; i < strLength; i++ {
go func(i int) {
defer wg.Done()
char := str[i]
random := rand.Intn(1000)
mutex.Lock()
obf := string(fmt.Sprintf("%v%v", string(char), random))
result = append(result, obf)
mutex.Unlock()
}(i)
}
wg.Wait()
allSaidAndDone := strings.Join(result, "")
fmt.Println(allSaidAndDone)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment