Skip to content

Instantly share code, notes, and snippets.

@oshinko
Last active April 13, 2022 02:42
Show Gist options
  • Save oshinko/38b3ebe4a1e5b453234ae7226bd35b22 to your computer and use it in GitHub Desktop.
Save oshinko/38b3ebe4a1e5b453234ae7226bd35b22 to your computer and use it in GitHub Desktop.
Hash the date
d = new Date()
s = [d.getFullYear(), d.getMonth() + 1, d.getDate()].join('/')
(async function(text, n) {
data = new TextEncoder().encode(text)
hash = await window.crypto.subtle.digest('SHA-1', data)
uint = new DataView(hash, 0).getUint32()
console.log(text, uint % n)
})(s, 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment