I would like to hash IDs into buckets such that
My strategy is to get an MD5 hash of the ID, convert it into a number and then mod it into a bucket.
val hash: Array[Byte] = MessageDigest.getInstance("MD5").digest("Hello")
val number: java.math.BigInteger = new BigInteger(hash)
val bucket = number.mod(new BigInteger("1000"))
Does this approach maintain the nice properties that MD5 provides? Would this achieve the goals above?
Your approach is sound (if slow), and maintains all the good properties of MD5 except collision resistance.
A lack of collision resistance is rarely a concern in a bucket selection algorithm though. Exploitation requires the system 1. to bucket millions of IDs provided by an untrusted party and 2. to depend on roughly uniform distribution for reliability and/or correctness.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With