Answer the question
In order to leave comments, you need to log in
How to get a number in the desired interval by hash?
In general, look, there is some kind of md5 hash. Let's say 220466675e31b9d20c051d5e57974150 is also a random number from 1 to infinity. You need to somehow combine this number, this hash and get a random number from 0 to 14. The algorithm is not important. Broke my head, please help
Answer the question
In order to leave comments, you need to log in
Check out the magic:
$a = '14';
$b = '220466675e31b9d20c051d5e57974150';
$c = $a.$b;
$res = substr($c, 2);
Do you really need a hash?) Can you score on it and come up with something only with the number that is attached to the hash?
If you need an algorithm ... Then we cut out all the letters from the hash, multiply by your number that goes to the hash, translate the resulting number into a 14-decimal system, take any character (for example, always the fifth), translate back to decimal :)
I won’t write an implementation example: )
Look at this class https://github.com/sagargp/coolsitebro/blob/master...
Converts a number to another number system, which can be represented by letters and numbers.
Thus, for example, you can make a link shortener as I did
https://github.com/pvolyntsev/url-shortener/blob/m...
How does the shortener work?
The long link is stored in the table, in each record a unique serial number
The number is converted into such a sequence of letters.
The transformation is two-way - you can spell out the serial number.
hexdec($hash), then add, then add and subtract the first few characters character by character until we get a number in the range 0-14.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question