mardi 29 novembre 2016

Make choice from array semi-randomly based on string

I have this problem. I'd like to make random a choice from array [1,2,3,4] based on arbitrary 6 letter string in such way that this choice is always same if string is same.

So if i have string 'dogdog' function would return always '3' for example, but '4' for 'bigcat' etc.

I think the solution might be first hashing the string. How could one convert hash string into choice from array?




Aucun commentaire:

Enregistrer un commentaire