-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
41 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package db | ||
|
||
import "math/rand" | ||
|
||
const ( | ||
strChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" // 62 characters | ||
) | ||
|
||
// Str constructs a random alphanumeric string of given length. | ||
func randStr(length int) string { | ||
chars := []byte{} | ||
MAIN_LOOP: | ||
for { | ||
val := rand.Int63() | ||
for i := 0; i < 10; i++ { | ||
v := int(val & 0x3f) // rightmost 6 bits | ||
if v >= 62 { // only 62 characters in strChars | ||
val >>= 6 | ||
continue | ||
} else { | ||
chars = append(chars, strChars[v]) | ||
if len(chars) == length { | ||
break MAIN_LOOP | ||
} | ||
val >>= 6 | ||
} | ||
} | ||
} | ||
|
||
return string(chars) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters