title: JavaScript - Generate random pixels on HTML5 canvas
body: <p>I want to create a random generated image (random colors), like <a href="https://image.ibb.co/buJkTb/1.png" rel="nofollow noreferrer">this one</a>. But, I want to do it in javascript, but for some reason I am getting black screen.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>var g=document . createElement( 'canvas').getContext('2d');
  g.canvas.width=g.canvas.height = 800;
  g.imgd = g.getImageData(0, 0, 800, 800);
  g.data = g.imgd.data;
  
  g.data.forEach((_, index) =&gt; (index &amp; 3) &lt; 3 &amp;&amp; (g.data[index] = Math.random()));
  g.putImageData(g.imgd, 0, 0);
  
  document.body.appendChild(g.canvas);;;
  </code></pre>
  
  <p>And i am getting black screen, and on some websites it is white screen. So what is what not working in my script? My english is not very good, but can someone explain what is wrong, my code dont'esnt working.</p>
  
  <p>I also tried different dimensions of canvas and I dont see any errors so what is wrong?</p>