Last active
March 4, 2020 12:25
-
-
Save annanay25/fa5af5a2a985d9cd913fc25ed5bad6b7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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)) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
TLDR; Can use the seed in different hash instances, and it should give same results.