Can we use randomization for our Hash Maps?


#1

Question

In the context of this exercise, can we use randomization for our Hash Maps when applying its functions?

Answer

No, this is because utilizing randomization for some of the functions of a Hash Map can be a bad idea and prevent us from being able to consistently retrieve the correct values.

For instance, if your hash() function utilized randomization in its calculation, you may end up with a different hash value each time you call the function. This is an issue because you should always be able to retrieve the same value with the same key. Randomization can break this, and return a different value for the same key when you run the function multiple times.

However, you can absolutely randomize values and parameters used in the function, but they should not be changed after those values are generated.