Is there a normal fast string encoding algorithm to get an eight-digit ID (used in the frontend, to bundle certain elements). Can you share?

Example : tab55925907 , where tab is the prefix and the other part is the ID obtained from a string of any length and from any characters (x1y2z3). It is possible to fill in with zeros if the string is less than 8 characters.

// p - prefix; s - string; func GenerateTargetId(s string, p string) string { result := p + s[:8] return result } 
  • How about hash.crc32 and hash.crc64 ?! - Fyodor Karpushov

2 answers 2

You can use an ASCII table.

 func makeID(s string)(x string){ var y int = 1 for i := 0; i < len(s)-1; i++ { y *= int(s[i]) } x = strconv.Itoa(y) x = x[0:8] x = "tab" + x return } 

Only it is necessary to monitor the string that is passed to the function.

  • add zeros to the front if the number is not large enough - sercxjo
  • Thanks, that is necessary, I think, ascii of norms. - alxshelepenok pm

See the hashing algorithm: MurMur3. At the output utint64. Implementation option: https://gowalker.org/github.com/spaolacci/murmur3