summaryrefslogtreecommitdiffstats
path: root/lib/hamming.go
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-09-05 10:39:10 -0400
committerrsiddharth <s@ricketyspace.net>2020-09-05 10:39:10 -0400
commitaa9f08f51abee3e0857d82f3d45ec3bd58420de7 (patch)
tree3abb5a34f412d5fda61451fda459af4b2a8a9dc3 /lib/hamming.go
parent46205268e4984389585a44336f2e1a3804c0ac8d (diff)
lib: add genKey
* lib/hamming.go (genKey): New function.
Diffstat (limited to 'lib/hamming.go')
-rw-r--r--lib/hamming.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/hamming.go b/lib/hamming.go
index c267c43..b2c46e9 100644
--- a/lib/hamming.go
+++ b/lib/hamming.go
@@ -3,6 +3,12 @@
package lib
+import "math/rand"
+
+func init() {
+ rand.Seed(42)
+}
+
func HammingDistance(a, b string) int {
if len(a) != len(b) {
return -1 // Fail.
@@ -25,3 +31,11 @@ func setBits(b byte) int {
}
return int(c)
}
+
+// Generates a key of size 'size' bytes.
+func genKey(size int) []byte {
+ bs := make([]byte, size, size)
+ rand.Read(bs)
+
+ return bs
+}