Skip to main content
CSS-Tricks
  • Articles
  • Videos
  • Almanac
  • Newsletter
  • Guides
  • DigitalOcean
  • DO Community
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
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
  • DigitalOcean
  • DigitalOcean Community
  • About DigitalOcean
  • Legal
  • Agency Coaching
  • Free Credit Offer
CSS-Tricks
  • Email
  • Guest Writing
  • Book
  • Advertising
Follow
  • Mastodon
  • Twitter
  • Instagram
  • YouTube
  • CodePen
  • iTunes
  • RSS
Back to Top