Miss any of our Open RFC calls?Watch the recordings here! »

random-number-arrays

1.0.11 • Public • Published

Generate Random Number or Array of Random Numbers within specified range on finger tips.

Install


> $ npm install random-number-arrays

Usage

> const Random = require('random-number-arrays);
> const options = { min: 0, max: 10 }
> Random(options);
> // => 4

> const options = { min:  0, max:  15, type:  'array', arraySize:  10 }
> Random(options);
> // => [ 2, 13, 4, 0, 11, 1, 8, 9, 12, 10 ]

> const options = { min:  0, max:  10, type:  'multi-array', arraySize:  10, numberOfArrays:  6 }
> Random(options);
> // => [ [ 2, 9, 1, 3, 6, 7, 9, 10, 1, 4 ],
  [ 3, 7, 7, 1, 4, 6, 4, 1, 8, 10 ],
  [ 10, 6, 7, 4, 10, 2, 7, 6, 1, 1 ],
  [ 5, 8, 0, 9, 3, 0, 0, 1, 6, 1 ],
  [ 10, 2, 2, 9, 6, 5, 4, 1, 0, 4 ],
  [ 9, 8, 6, 4, 1, 3, 4, 2, 0, 9 ] ]

> const  options = { min:  1, max:  5, type:  'array', arraySize:  5, unique:  true,
                        data: [{ name:  'Zubair', age:  '24' },
                               { name:  'Faraz', age:  '26' },
                               { name:  'Faris', age:  '23' },
                               { name:  'Umer', age:  '26' },
                               { name:  'Aahad', age:  '24' },
                               { name:  'Rohail', age:  '27' },
                               { name:  'Taj', age:  '24' }]
                    }
> Random(options);
> // [ { name: 'Aahad', age: '24' },
  { name: 'Zubair', age: '24' },
  { name: 'Faraz', age: '26' },
  { name: 'Zain', age: '24' },
  { name: 'Sohaib', age: '25' } ]
 

Options:

| Key             |   Type   |  Default  | Description                                                                                                                                         |
|---------------- |:-------: |:--------: |---------------------------------------------------------------------------------------------------------------------------------------------------- |
| min             |  Number  |     0     | Range Minimum Number                                                                                                                                |
| max             |  Number  |    100    | Range Maximum Number                                                                                                                                |
| type            |  String  | 'number'  | For single random number, use 'number'. For single array of random numbers, use 'array'. For multiple array of random numbers, use 'multi-array'.   |
| arraySize       |  Number  |     5     | For type='array' or type='multi-array', specify the size of the array.                                                                              |
| numberOfArrays  |  Number  |     2     | For type='multi-array', specify number of random number arrays to be generated.                                                                     |
| unique          | Boolean  |   false   | Return unique values for type array provided that array size should be less than numbers count in provided range.                                   |
| data            | Array    |   null    | (Optional) For type='array' or type='multi-array', provide your own data to get random elements.                                                    |

Install

npm i random-number-arrays

DownloadsWeekly Downloads

3

Version

1.0.11

License

MIT

Unpacked Size

8.32 kB

Total Files

5

Last publish

Collaborators

  • avatar