What is the point of hash = (prime * hash + b) % 100 While looking though some code base I found the function which has no explanation and does something like this (pseudocode)

func something(str, num) { // str is a string, num is a number from 0 to 100
   hash = 0
   prime = 17
   for b in byte_array_of_base64decode(str){
       hash = (prime * hash + b) % 100
   }
   return hash &lt; num
}


There is no explanation what the function suppose to do and the name of it also does not give any clue.

I assume that if this does any useful thing, it has something to do with hashing or sampling. Does anyone know the point of this function?
Distributing objects among buckets of a hash map

This looks like an (old) textbook algorithm for allocating elements in a hash map or hash table. Other than the last line, which doesn't really make sense, it would be used calculate which hash map 'bucket' to use for putting/getting this item, as you need to calculate a simple, cheap and fast (so, generally not a cryptographic hash, but a few multiplications) code that would be an integer in the range from 0 to length of the map backing array (probably 100 in this case) that preferably is different for nonidentical similar objects to reduce the number of collisions.

A textbook example from Algorithms 4th ed by Sedgewick&amp;Wayne, the similarity should be obvious:

int hash = 0;
for (int i = 0; i &lt; s.length(); i++)
    hash = (R * hash + s.charAt(i)) % M;


This has nothing to do with cryptography, though. Nowadays many standard libraries try to use a cryptographically unpredictable algorithm for hashmap hashes to prevent a risk of DoS attacks by data engineered to induce worst case performance, but this example is not one of these.