bool

  • chance.bool()
  • chance.bool({likelihood: 30})

Use: Return a random boolean value (true or false).

chance.bool();
// true

The default likelihood of success (returning true) is 50%. Can optionally specify the likelihood in percent:

chance.bool({likelihood: 30});
=> false

In this case only a 30% likelihood of true, and a 70% likelihood of false.

character

  • chance.character()
  • chance.character({pool: 'abcde'})
  • chance.character({alpha: true})
  • chance.character({casing: 'lower'})
  • chance.character({symbols: true})

Use: Return a random character.

chance.character();
=> 'v'

By default it will return a string with random character from the following pool.

'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()'

Optionally specify a pool and the character will be generated with characters only from that pool.

chance.character({pool: 'abcde'});
=> 'c'

Optionally specify alpha for only an alphanumeric character.

chance.character({alpha: true});
=> 'N'

Default includes both upper and lower case. It's possible to specify one or the other.

chance.character({casing: 'lower'});
=> 'j'

Note, wanted to call this key just case but unfortunately that's a reserved word in JavaScript for use in a switch statement

Optionally return only symbols

chance.character({symbols: true});
=> '%'