Skip to content

Instantly share code, notes, and snippets.

@annanay25
Last active March 4, 2020 12:25
Show Gist options
  • Save annanay25/fa5af5a2a985d9cd913fc25ed5bad6b7 to your computer and use it in GitHub Desktop.
Save annanay25/fa5af5a2a985d9cd913fc25ed5bad6b7 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"hash/maphash"
"math/rand"
)
func main() {
b := make([]byte, 4)
rand.Read(b)
s := maphash.MakeSeed()
fmt.Println("Seed", s)
hasher := maphash.Hash{}
hasher.SetSeed(s)
fmt.Println("Seed", hasher.Seed())
hasher.Write(b)
idSum := []byte{}
fmt.Println("Hash", hasher.Sum(idSum))
hasher1 := maphash.Hash{}
hasher1.SetSeed(s)
fmt.Println("Seed", hasher1.Seed())
hasher1.Write(b)
idSum1 := []byte{}
fmt.Println("Hash", hasher1.Sum(idSum1))
}
@annanay25
Copy link
Author

annanay25 commented Mar 4, 2020

Output:

Seed {17337154316731309817}
Seed {17337154316731309817}
Hash [113 81 246 19 106 240 236 115]
Seed {17337154316731309817}
Hash [113 81 246 19 106 240 236 115]

TLDR; Can use the seed in different hash instances, and it should give same results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment