Index: common/dirwalk/tests/tools/gendir/random_utils.go |
diff --git a/common/dirwalk/tests/tools/gendir/random_utils.go b/common/dirwalk/tests/tools/gendir/random_utils.go |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cde63d8bf209ac3260d4ade840e2098cdafb6beb |
--- /dev/null |
+++ b/common/dirwalk/tests/tools/gendir/random_utils.go |
@@ -0,0 +1,37 @@ |
+// Copyright 2016 The LUCI Authors. All rights reserved. |
+// Use of this source code is governed under the Apache License, Version 2.0 |
+// that can be found in the LICENSE file. |
+ |
+package main |
+ |
+import ( |
+ "math/rand" |
+) |
+ |
+var textChars = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-.") |
+ |
+func randChar(r *rand.Rand, runes []rune) rune { |
+ return runes[r.Intn(len(runes))] |
+} |
+ |
+func randStr(r *rand.Rand, length uint64, runes []rune) string { |
+ str := make([]rune, length) |
+ for i := range str { |
+ str[i] = randChar(r, runes) |
+ } |
+ return string(str) |
+} |
+ |
+func randBetween(r *rand.Rand, min uint64, max uint64) uint64 { |
+ if min == max { |
+ return min |
+ } |
+ return uint64(r.Int63n(int64(max-min))) + min |
+} |
+ |
+// FIXME: Maybe some UTF-8 characters? |
+var filenameChars = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-") |
+ |
+func filenameRandom(r *rand.Rand, length uint64) string { |
+ return randStr(r, length, filenameChars) |
+} |