I have many strings. Each string something like:
- "i_love_pizza_123"
- "whatever_this_is_now_later"
- "programming_is_awesome"
- "stack_overflow_ftw"
- ...etc
I need to be able to convert each string to a random number, 1-10. Each time that string gets converted, it should consistently be the same number. A sampling of strings, even with similar text should result in a fairly even spread of values 1-10.
My first thought was to do something like md5($string), then break down a-z,0-9 into ten roughly-equal groups, determine where the first character of the hash falls, and put it in that group. But, md5 hashing seems to cause the results to start with the same few characters (e,d,f,1,...etc) much more often than the others.
Thoughts on a good method to consistently convert a string to a random/repeatable number, 1-10?
Aucun commentaire:
Enregistrer un commentaire