Skip to content

Instantly share code, notes, and snippets.

@carlosmcevilly
Last active December 12, 2021 18:20
Show Gist options
  • Save carlosmcevilly/088205b1a8571ebb029eba97e320408e to your computer and use it in GitHub Desktop.
Save carlosmcevilly/088205b1a8571ebb029eba97e320408e to your computer and use it in GitHub Desktop.
generate a single random hex color string
function randomColor () {
# assuming 24-bit color
range_max=$((256 * 256 * 256))
printf "%06x\n" $(((((RANDOM*RANDOM)+(RANDOM*RANDOM))+RANDOM)%range_max))
}
# test
# $ for in in {0..99999}; do randomColor; done | sort | uniq | wc -l
# (should output a number roughly near 99700)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment