D
D
Dorothy2017-09-07 11:32:41
PHP
Dorothy, 2017-09-07 11:32:41

What is the function algorithm to translate a string into a unique number?

Hello.
It is necessary to make a function, the input of which is given a string, and the output is a number that is always the same for this particular string. The number must be between 0 and PHP_INT_MAX.
The results should be evenly distributed. For example, if you supply string representations of numbers from 0 to PHP_INT_MAX as input, so that the results of the function ideally repeat as few times as possible.
For example:

f('1') // 6484845
f('11') // 2156165
f('111') // 59544206

There was an idea to do this:
Take the first 7 bytes of md5 from the input string and translate into 10 SS. But, as far as I know, md5 results do not often have many zeros in a row. As a result of this, the numbers built according to this algorithm will be skewed upwards, and there will be almost no numbers, as it seems to me, closer to 0.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2017-09-07
@Dorothy

hashids.org/php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question