MCPcopy
hub / github.com/smallstep/cli / randWithDictionary

Function randWithDictionary

command/crypto/rand/rand.go:212–243  ·  view source on GitHub ↗
(dictionary string, length int)

Source from the content-addressed store, hash-verified

210}
211
212func randWithDictionary(dictionary string, length int) error {
213 file, err := os.Open(dictionary)
214 if err != nil {
215 return err
216 }
217 defer file.Close()
218
219 scanner := bufio.NewScanner(file)
220 words := make([]string, 0, 1024)
221 for scanner.Scan() {
222 words = append(words, strings.TrimSpace(scanner.Text()))
223 }
224 if err := scanner.Err(); err != nil {
225 return err
226 }
227
228 var s string
229
230 for i := 0; i < length; i++ {
231 bn, err := rand.Int(rand.Reader, big.NewInt(int64(len(words))))
232 if err != nil {
233 return err
234 }
235 s += words[bn.Int64()]
236 if i != length-1 {
237 s += "-"
238 }
239 }
240
241 fmt.Println(s)
242 return nil
243}

Callers 1

randActionFunction · 0.85

Calls 1

CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…