Andrew Thorp

Random generation for JavaScript with Chance

Chance, by Victor Quinn, is a small (~18k) JavaScript library that makes random generation dead simple! You can generate random numbers, strings, addresses, dice, and more. Usage is simple:

<script src="chance.js"></script>
  var my_chance = new Chance();
  console.log(my_chance.bool()); // either true or false
  console.log(; // (xxx) xxx-xxxx
  console.log(my_chance.paragraph({sentences: 1})); // random paragraph with one sentence
  console.log(my_chance.sentence({words: 5})); // random sentence with five words

There are a ton of options, and you can view them all at the chance website, or view the source at GitHub.


Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00