Skip to content

Instantly share code, notes, and snippets.

@clayadavis
Last active August 10, 2021 18:12
Show Gist options
  • Save clayadavis/ee44fadb8ea1db6d9629cde8f9eb7d18 to your computer and use it in GitHub Desktop.
Save clayadavis/ee44fadb8ea1db6d9629cde8f9eb7d18 to your computer and use it in GitHub Desktop.
Random die face
const d6 = () => String.fromCodePoint(0x2680 + Math.floor(Math.random() * 6))
function d6() {
const faceIdx = Math.floor(Math.random() * 6);
const codePoint = 0x2680 + faceIdx;
return String.fromCodePoint(codePoint)
}
@clayadavis
Copy link
Author

String.fromCharCode also works here and has better browser compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment