title: javascript random color with 7digits must
body: <p>I found the following awesome script to create a random color with javascript.</p>
  <pre><code>var randColor = '#'+(Math.random()*0xFFFFFF&lt;&lt;0).toString(16);
  </code></pre>
  <p>only problem I have with this script is that it's not garanteed that it returns a normal 7digit hex string.</p>
  <p>sometimes it's just 6 digits long like #e1d19.</p>
  <p>is there a way to kind of force a 7 digit hex value?</p>
  <p>thank you for your help.</p>
  <p>edit: this is my actual problem:</p>
  <pre><code>function randColor() {
      var randColor = '#'+(Math.random()*0xFFFFFF&lt;&lt;0).toString(16);
      return randColor;
  }
  
  for (var i=0; i&lt;100; i++) {
      $(&quot;#colorpicker&quot;).append(&quot;&lt;div class='color' title=&quot;+randColor()+&quot; style='background:&quot;+randColor()+&quot;'&gt;&lt;/div&gt;&quot;);
  }
  </code></pre>
  <p>I'm creating little divs with a random color, when I click on them I grab their title attribute and I'm coloring the background of my body.</p>
  <p>however currently my code ends in</p>
  <pre><code>&lt;div style=&quot;background:rgb(176, 249, 252);&quot; title=&quot;#8bc47d&quot; class=&quot;color&quot;&gt;&lt;/div&gt;
  </code></pre>
  <p>so when I grab the title attribute the color I'm giving my body is a different one than the little div shows.</p>