deletionChallenge generates a random string
()
| 79 | |
| 80 | // deletionChallenge generates a random string |
| 81 | func deletionChallenge() string { |
| 82 | const n = 8 // desired length of the random string |
| 83 | |
| 84 | b := make([]byte, n) |
| 85 | _, err := rand.Read(b) |
| 86 | if err != nil { |
| 87 | panic(err) |
| 88 | } |
| 89 | |
| 90 | const letterBytes = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789" |
| 91 | var result string |
| 92 | |
| 93 | for i := 0; i < n; i++ { |
| 94 | result += string(letterBytes[int(b[i])%len(letterBytes)]) |
| 95 | if i == 3 { |
| 96 | result += "-" |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | return result |
| 101 | } |