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

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)
Our Learning Partner
Frontend Masters logo
Frontend Masters

Need front-end development training?

Frontend Masters is the best place to get it. They have courses on all the most important front-end technologies, from React to CSS, from Vue to D3, and beyond with Node.js and Full Stack.

CSS-Tricks is created by Chris and a team of swell people.

Keep up to date on web dev

with our hand-crafted weekly newsletter

Tech
  • WordPress (CMS)
  • Jetpack (Search, Backup)
  • WooCommerce (eCommerce)
  • Local (Development)
Hosting
  • Flywheel
Family
  • CodePen
  • ShopTalk Show
Minisites
  • The Power of Serverless
  • Upcoming Conferences
  • Coding Fonts
Contact
  • Email
  • Sponsorship Info
  • Guest Writing
Buy
  • Posters & Swag
  • Membership
Follow
  • Twitter
  • Instagram
  • YouTube
  • CodePen
  • GitHub
  • iTunes
  • RSS
Back to Top