Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
100,000 の多かれ少なかれランダムな文字列のデータベースがあり、各文字列から 1 から 500 までの数値を生成したいとします。
私のメソッドは常に同じ数値を生成し (同じ文字列が与えられた場合)、1 から 500 までの数値を均等に分散する必要があります。
何か案は?
ハッシュ関数が必要なようです。モジュラス演算子crc32を使用できます:
crc32
echo abs(crc32("hello world")) % 500 + 1;