Created
May 30, 2022 15:47
-
-
Save jahilldev/9e5a0553ae57d3548f192d53a254204c to your computer and use it in GitHub Desktop.
Generate a non-secure reproducible hash from an input seed value (not suitable for passwords, or sensitive data)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getHash(value, length = 16) { | |
let hash = 0; | |
for (let index = 0; index < value.length; index++) { | |
hash = (hash << 5) - hash + value.charCodeAt(index); | |
hash = hash & hash; | |
} | |
hash = Math.abs(hash); | |
return `${hash}`.padStart(length, '0').substring(-1, length); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment