(java) - Hash function to distribute Strings uniformly in a given range?

半城伤御伤魂 提交于 2021-02-19 05:22:03

问题


So ... I'm looking for a hash function that -- assuming no input skew -- will distribute nonempty Strings of (up to) 16 bytes "reasonably uniformly" onto a range [0..n] where n is user input but does not change over time.

And I should be able to argue why the function should provide that "resonably uniform" distribution.

In the end, all I need is a Java implementation of the hash function for use in a server and a reason "why" this hash function is suitable. So I'm looking less for "perfect uniform distribution" (if such a thing even exists) and more for "reasonably fast".

Still, I've never been much of a mathematician, so ...

  • is there some native Java functionality that would provide such a hash?
  • or any suggestion on how to come up with such a hash function?

来源:https://stackoverflow.com/questions/39791109/java-hash-function-to-distribute-strings-uniformly-in-a-given-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!