title: Best way to generate a random color in javascript?
body: <p>What is the best way to generate a random color in JavaScript Without using any frameworks...</p>
  
  <p>Here are a couple of solutions I came up with:</p>
  
  <pre><code>function get_random_color() 
  {
      var color = "";
      for(var i = 0; i &lt; 3; i++) {
          var sub = Math.floor(Math.random() * 256).toString(16);
          color += (sub.length == 1 ? "0" + sub : sub);
      }
      return "#" + color;
  }
  
  function get_rand_color()
  {
      var color = Math.floor(Math.random() * Math.pow(256, 3)).toString(16);
      while(color.length &lt; 6) {
          color = "0" + color;
      }
      return "#" + color;
  }
  </code></pre>
  
  <p>Are there better ways to do it?</p>