Say I have a regular Javascript array of around 500 words
ie
var words = ['apple', 'banana', cherry'...
and a Keccak256 (SHA-3) hash that is generated then stored. I need to use the hash to select a value in the array. Every time the same hash is given, the same value must be selected again. It does not matter which word is initially selected, but all words must have a roughly equal chance of being selected.
The hash is made up of numbers 0-9 and letters a-f, example:
5f16f4c7f149ac4f9510d9cf8cf384038ad348b3bcdc01915f95de12df9d1b02
I would like to use the first 3 characters of the hash to do this, ie 5f1
, but if more characters are needed, that's okay.
Tried a few things here, but it hasn't worked out too well, and I end up picking some words more than others. What would be a good way to go about doing this?
Thanks in advance!