Random RBG in Javascript - Javascript Math

Javascript examples for Math:random

Description

Random RBG in Javascript

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from  w  w w  .  jav a 2  s.c  o  m*/
function random_rgba() {
    var o = Math.round, r = Math.random, s = 255;
    return 'rgba(' + o(r()*s) + ',' + o(r()*s) + ',' + o(r()*s) + ',' + r().toFixed(1) + ')';
}
for (var i=0; i<10; i++) {
    console.log( random_rgba() )
}
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials