How to generate hash number of a string in Go?

前端 未结 2 1278
遇见更好的自我
遇见更好的自我 2021-02-02 07:05

For example:

hash(\"HelloWorld\") = 1234567

Is there any built-in function could do this ?

Thanks.

2条回答
  •  不要未来只要你来
    2021-02-02 07:21

    Here is a function you could use to generate a hash number:

    // FNV32a hashes using fnv32a algorithm
    func FNV32a(text string) uint32 {
        algorithm := fnv.New32a()
        algorithm.Write([]byte(text))
        return algorithm.Sum32()
    }
    

    I put together a group of those utility hash functions here: https://github.com/shomali11/util

    You will find FNV32, FNV32a, FNV64, FNV64a, MD5, SHA1, SHA256 and SHA512

提交回复
热议问题