How to generate random color in RGBA format with JavaScript

1 Answer

0 votes
function random_rgba() {
    let ro = Math.round, r = Math.random, s = 255;
    return 'rgba(' + ro(r()*s) + ',' + ro(r()*s) + ',' + ro(r()*s) + ',' + r().toFixed(1) + ')';
}

const color = random_rgba();
 
console.log(color);
 
 
     
     
     
/*
run:
     
"rgba(104,187,175,0.9)"

     
*/

 



answered May 28, 2021 by avibootz

Related questions

2 answers 158 views
1 answer 252 views
1 answer 147 views
1 answer 126 views
2 answers 152 views
...