diff options
| author | Jimmy Cann <[email protected]> | 2017-08-26 09:47:24 +1000 |
|---|---|---|
| committer | Marak <[email protected]> | 2018-09-21 09:46:16 -0400 |
| commit | 56aa8121f254482ae2f200605402c9d4eb917abe (patch) | |
| tree | b2ba5f1d47ac31203d11c2181a5c7dd6d0856902 /lib | |
| parent | 3a4bb358614c1e1f5d73f4df45c13a1a7aa013d7 (diff) | |
| download | faker-56aa8121f254482ae2f200605402c9d4eb917abe.tar.xz faker-56aa8121f254482ae2f200605402c9d4eb917abe.zip | |
[api] Add method `faker.random.float`
- Extends the `faker.random.number` float to automatically return a 0.01 precision float
- First parameter is set as the precision value
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/random.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/random.js b/lib/random.js index 8dccf376..a2e42904 100644 --- a/lib/random.js +++ b/lib/random.js @@ -57,6 +57,26 @@ function Random (faker, seed) { } /** + * returns a single random floating-point number based on a max number or range + * + * @method faker.random.float + * @param {mixed} options + */ + this.float = function (options) { + if (typeof options === "number") { + options = { + precision: options + }; + } + + options = options || {}; + + return this.number(Object.assign({}, options, { + precision: options.precision || 0.01 + })) + } + + /** * takes an array and returns a random element of the array * * @method faker.random.arrayElement |
