Hash of unique value = unique hash?
问题 Theoretically does hashing a unique value yield a unique value? Let's say I have a DB table with 2 columns: id and code. id is an auto-incrementing int and code is a varchar. If I do ... $code = sha1($id); ... and then store $code into the same row as $id. Will my code column be unique as well? What about if I append the current time? eg: $code = sha1($id . time()); Thanks. 回答1: In general, the answer is no. This is trivial to show: SHA-1 has 2^160 different outputs - 160 bits, but there are