aboutsummaryrefslogtreecommitdiff
path: root/lib/text
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2018-08-28 01:40:34 +0700
committerShulhan <ms@kilabit.info>2018-08-28 01:40:34 +0700
commit89558a8da2e9efbb6b71dd26674e82e176f95ec1 (patch)
treeba5d64100323ddd5c3a8c679eb3751956fe17b54 /lib/text
parentf58736a1a3d4384fdef6d873e6ec6878784451b0 (diff)
downloadpakakeh.go-89558a8da2e9efbb6b71dd26674e82e176f95ec1.tar.xz
lib/text: add function to generate fixed random characters
Diffstat (limited to 'lib/text')
-rw-r--r--lib/text/bytes.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/text/bytes.go b/lib/text/bytes.go
index 6a4487f3..fa398390 100644
--- a/lib/text/bytes.go
+++ b/lib/text/bytes.go
@@ -3,6 +3,7 @@ package text
import (
"bytes"
"fmt"
+ "math/rand"
"strconv"
)
@@ -19,6 +20,10 @@ const (
bLineFeed = '\n'
bCarReturn = '\r'
bTab = '\t'
+ ASCIILetters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ HexaLETTERS = "0123456789ABCDEF"
+ HexaLetters = "0123456789abcedfABCDEF"
+ Hexaletters = "0123456789abcedf"
)
//
@@ -166,3 +171,16 @@ func BytesJSONUnescape(in []byte, strict bool) ([]byte, error) {
return buf.Bytes(), nil
}
+
+//
+// Random generate random sequence of value from seed with fixed length.
+//
+// This function assume that random generator has been seeded.
+//
+func Random(seed []byte, n int) []byte {
+ b := make([]byte, n)
+ for x := 0; x < n; x++ {
+ b[x] = seed[rand.Intn(len(seed))]
+ }
+ return b
+}