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 155 views
1 answer 248 views
1 answer 145 views
1 answer 123 views
2 answers 150 views
...