I have the requirement to generate random but reproducible numbers for arbitrary strings in Java. For the same requirement in SQL I have used the function ORA_HASH provided by Oracle:
ORA_HASH generates hash values for an expression. You can use it to randomly assign a set of values into several buckets for analysis, or to generate a set of random numbers.
The function has three parameters: the expression to hash, the maximum bucket number, and a seed. For my purposes in SQL the maximum bucket number has been set to the maximum allowed value.
My idea is to implement ORA_HASH in Java (with maximum bucket number). For that purpose I want to combine String.hashCode() with a random seed.
However, I have no idea how to combine the hashcode and the seed such that
- no additional hash collision emerges (
xorprobably don't satisfy this requirement) - neither the seed nor the original expressions are (easily) reproducible from the result (a simple
+don't satisfy this requirement)
Any idea for a better solution?
Aucun commentaire:
Enregistrer un commentaire