Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: common/dirwalk/tests/tools/gendir/random_utils.go

Issue 2054763004: luci-go/common/dirwalk: Code for walking a directory tree efficiently Base URL: https://github.com/luci/luci-go@master
Patch Set: Major rewrite of the code. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698