random-decimal

1.0.2 • Public • Published

random-decimal

Return a random decimal.

MIT License

build:? coverage:?

Install

$ npm install --save random-decimal

Usage

For more use-cases see the tests

var randomDecimal = require('random-decimal');
 
// API
// - randomDecimal([options])
 
// options
// - min
// - max
// - fixed

By default it will return a fixed number of at most 4 digits after the decimal.

randomDecimal();
// range: 0 to 9007199254740992
// => 211920142886.5024

Note: at most 4 digits. This because, unless we returned trailing zeroes (which aren’t allowed on the JavaScript float) we can’t guarantee 4 digits after the decimal. So if random chance comes back with 82383854.2000 then 82383854.2 is what will be returned.

Can optionally provide min and max:

randomDecimal({max: 5});
// => 2.3785
 
randomDecimal({min:10, max: 100});
// => 66.7269

Note: these min and max are inclusive, so they are included in the range.

To retrieve a set number of fixed digits after the decimal, provide it as an option:

randomDecimal({fixed: 7});
// => 749512327.7447168

Or combine them:

randomDecimal({min: 0, max: 100, fixed: 8});
// => 45.92367599

Related

Contributing

Pull requests and stars are highly welcome.

For bugs and feature requests, please create an issue.

Package Sidebar

Install

npm i random-decimal

Weekly Downloads

14

Version

1.0.2

License

MIT

Last publish

Collaborators

  • bubkoo