×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Massimo Zappino
Added: Feb 2, 2011 11:26 AM
Views: 150
Tags: random hex color
  1. /* Slowest but shortest. */
  2. "#000000".replace(/0/g,function(){return (~~(Math.random()*16)).toString(16);});    
  3.  
  4. /* Good performance with small size. */
  5. "#"+(function(a,b){while(a--){b+=""+(~~(Math.random()*16)).toString(16);} return b;})(6,"");
  6.  
  7. /* Remy Sharp provided one that's the fastest but a little bit too long */
  8. (function(h){return '#000000'.substr(0,7-h.length)+h})((~~(Math.random()*(1<<24))).toString(16))