Created
November 17, 2013 09:29
-
-
Save ivankahl/7511259 to your computer and use it in GitHub Desktop.
This function generates random hex colours. Useful for random HTML pages.
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() | |
{ | |
var l=["A","B","C","D","E","F",0,1,2,3,4,5,6,7,8,9], // We declare our list with all the possible characters that can be used | |
c="", // Our variable we are going to use to store our final hex colour in | |
i=0; // The i variable we will use in our while loop | |
while(i<6) // Loop the code 6 times so that we get a 6-byte string (i.e. the hex colour) | |
{ | |
c+=l[Math.floor(Math.random()*16)]; // Get a random value from the list | |
i++ // Increment i by 1 | |
} | |
return(c) // Return the value to the user | |
} |
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(){var l=["A","B","C","D","E","F",0,1,2,3,4,5,6,7,8,9],c="",i=0;while(i<6){c+=l[Math.floor(Math.random()*16)];i++}return(c)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment