OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. |
| 4 |
| 5 package main |
| 6 |
| 7 import ( |
| 8 "math/rand" |
| 9 ) |
| 10 |
| 11 var textChars = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123
456789-.") |
| 12 |
| 13 func randChar(r *rand.Rand, runes []rune) rune { |
| 14 return runes[r.Intn(len(runes))] |
| 15 } |
| 16 |
| 17 func randStr(r *rand.Rand, length uint64, runes []rune) string { |
| 18 str := make([]rune, length) |
| 19 for i := range str { |
| 20 str[i] = randChar(r, runes) |
| 21 } |
| 22 return string(str) |
| 23 } |
| 24 |
| 25 func randBetween(r *rand.Rand, min uint64, max uint64) uint64 { |
| 26 if min == max { |
| 27 return min |
| 28 } |
| 29 return uint64(r.Int63n(int64(max-min))) + min |
| 30 } |
| 31 |
| 32 // FIXME: Maybe some UTF-8 characters? |
| 33 var fileNameChars = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789-") |
| 34 |
| 35 func fileNameRandom(r *rand.Rand, length uint64) string { |
| 36 return randStr(r, length, fileNameChars) |
| 37 } |
OLD | NEW |