Created
September 14, 2018 04:22
-
-
Save selfup/e6dfc0191017ea9ffbb6e5959710c4f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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