Short Python alphanumeric hash with minimal collisions

后端 未结 5 1871
隐瞒了意图╮
隐瞒了意图╮ 2020-12-16 09:32

I\'d like to set non-integer primary keys for a table using some kind of hash function. md5() seems to be kind of long (32-characters).

What are some alternative

5条回答
  •  北海茫月
    2020-12-16 10:07

    You can use something like base 32 notation. It is more compact than decimal notation, case insensitive and collision-free. Just encode a plain old sequence number to generate a short hash-like code.

    If the key is not for human consumption, you can use base 64 notation, which is case sensitive but a little more compact.

    See http://code.google.com/p/py-cupom/ for an example.

提交回复
热议问题