Skip to main content
CSS-Tricks
  • Articles
  • Alamanac
  • Guides
  • Videos
  • Books
  • Newsletter
Search

Articles Tagged
random

2 Articles
{
,

}
Direct link to the article Lots of Ways to Use Math.random() in JavaScript
JavaScript math random

Lots of Ways to Use Math.random() in JavaScript

Math.random() is an API in JavaScript. It is a function that gives you a random number. The number returned will be between 0 (inclusive, as in, it’s possible for an actual 0 to be returned) and 1 (exclusive, as in, …

Avatar of Jwahir Sundai
Jwahir Sundai on Nov 30, 2020
Direct link to the article How To Generate a Random Color in JavaScript
color hex random

How To Generate a Random Color in JavaScript

Here’s a quicky (there is a PHP version too):

var randomColor = Math.floor(Math.random()*16777215).toString(16);

See the Pen
Generate New Random Hex Color with JavaScript
by Chris Coyier (@chriscoyier)
on CodePen.

If you’d prefer they are a bit more …

Avatar of Chris Coyier
Chris Coyier on Dec 10, 2009 (Updated on Feb 19, 2020)

CSS-Tricks is powered by DigitalOcean.

Keep up to date on web dev

with our hand-crafted newsletter

DigitalOcean
  • About DO
  • Cloudways hosting
  • Legal stuff
  • Get free credit!
CSS-Tricks
  • Write for us!
  • Advertise with us
  • Contact us
Social
  • RSS Feeds
  • CodePen
  • Mastodon
  • X
Back to Top