hashStringBetween()function

hashStringBetween(str: string, min = 0, max = 256): number
ParamType
strstring
The string to hash. required
minunknown
The inclusive lower bound of the output range. Defaults to 0. Defaults to 0
maxunknown
The exclusive upper bound of the output range. Defaults to 256. Defaults to 256
Return
number
A number in the range min to max derived from the string.

Hash a string into an idempotent number wrapped between two values.

  • Useful for deterministically mapping a string into a fixed range, e.g. a colour or bucket index.

Examples

hashStringBetween("abc", 0, 10) // 4