Last active
December 12, 2021 18:20
-
-
Save carlosmcevilly/088205b1a8571ebb029eba97e320408e to your computer and use it in GitHub Desktop.
generate a single random hex color string
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 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