An integer hash ranging from a string

I am writing a function that should return a "random" number from a given string, starting with:

function hashNumberBetween(str, start, end){
  ....
  return num;
}

// same string and same length return same number
hashNumberBetween('getjnigejgr', 0, 10); // 4
hashNumberBetween('getjnigejgr', 0, 10); // 4

// but, same string and different length return different number
hashNumberBetween('getjnigejgr', 0, 32); // 15

hashNumberBetween('jukojmnktgo', 0, 10); // 6

What is the right way to achieve the same combination with the same string? I believe this is some kind of hash function. Any online resource I can look at? This may be a very simple question, but I don’t know how to look for it.

+4
source share
2 answers

Is this something like a password in a database?

You pass some password string myPassword123=> convert it to crc32 / md5 etc. => database search for the generated string => returns the username by password.

0
source

, , .

- .

, - Javascript google ( ).

, , ,

0

Source: https://habr.com/ru/post/1533917/


All Articles