aboutsummaryrefslogtreecommitdiff
path: root/lib/bytes/random.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bytes/random.go')
-rw-r--r--lib/bytes/random.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/bytes/random.go b/lib/bytes/random.go
new file mode 100644
index 00000000..73945788
--- /dev/null
+++ b/lib/bytes/random.go
@@ -0,0 +1,22 @@
+// Copyright 2018, Shulhan <ms@kilabit.info>. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package bytes
+
+import (
+ "math/rand"
+)
+
+//
+// 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
+}