|
| 1 | +<h1 align="center">@compactjs/random</h1> |
| 2 | +<h3 align="center">Simple module to generate random values from a given range or array.</h3> |
| 3 | +<p align="center"> |
| 4 | + <a href="https://www.npmjs.com/package/@compactjs/random" target="_blank"> |
| 5 | + <img alt="Version" src="https://img.shields.io/npm/v/@compactjs/random.svg"> |
| 6 | + </a> |
| 7 | + <a href="https://github.com/CompactJS/random/blob/master/LICENSE" target="_blank"> |
| 8 | + <img alt="License: MIT" src="https://img.shields.io/github/license/compactjs/random" /> |
| 9 | + </a> |
| 10 | +</p> |
| 11 | +<p align="center"> |
| 12 | + · |
| 13 | + <a href="https://github.com/CompactJS/random#readme">Homepage</a> |
| 14 | + · |
| 15 | + <a href="https://github.com/CompactJS/random/issues">Report Bug / Request Feature</a> |
| 16 | + · |
| 17 | +</p> |
| 18 | + |
| 19 | +## Table of Contents |
| 20 | + |
| 21 | +- [Installation](#Install) |
| 22 | +- [Usage](#usage) |
| 23 | +- [Test](#run-tests) |
| 24 | +- [Contact](#contact) |
| 25 | +- [Contributing](#Contributing) |
| 26 | +- [License](#license) |
| 27 | + |
| 28 | +## Install |
| 29 | + |
| 30 | +### NPM: |
| 31 | + |
| 32 | +```sh |
| 33 | +npm install @compactjs/random |
| 34 | +``` |
| 35 | + |
| 36 | +## Usage |
| 37 | + |
| 38 | +```typescript |
| 39 | +/** |
| 40 | + * Returns a pseudo random number between min and max. |
| 41 | + * (min inclusive, max exclusive) |
| 42 | + * Max can be smaller than min. |
| 43 | + * If max is not omitted, between 0 and min. |
| 44 | + * If min is not omitted, between 0 and 1. |
| 45 | + */ |
| 46 | +function random(min?: number, max?: number): number; |
| 47 | + |
| 48 | +/** |
| 49 | + * Returns a random item from a given array |
| 50 | + * @param choices to select from |
| 51 | + */ |
| 52 | +function pick(choices: any[]): any; |
| 53 | +``` |
| 54 | + |
| 55 | +### As module: |
| 56 | + |
| 57 | +```javascript |
| 58 | +import { random, pick } from '@compactjs/random'; |
| 59 | +``` |
| 60 | + |
| 61 | +### Example: |
| 62 | + |
| 63 | +```javascript |
| 64 | +random(10, 100); // => random value between (including) 10 and 100 |
| 65 | +random(10); // => random value between 0 and 10 |
| 66 | +random(); // => random value between 0 and 1 |
| 67 | + |
| 68 | +pick([0, 1, 2, 3]); // => picks random value from 0,1,2,3 |
| 69 | +``` |
| 70 | + |
| 71 | +## Run tests |
| 72 | + |
| 73 | +```sh |
| 74 | +npm run test |
| 75 | +``` |
| 76 | + |
| 77 | +## Contact |
| 78 | + |
| 79 | +👤 **Timo Bechtel** |
| 80 | + |
| 81 | +- Website: https://timobechtel.com |
| 82 | +- Twitter: [@TimoBechtel](https://twitter.com/TimoBechtel) |
| 83 | +- GitHub: [@TimoBechtel](https://github.com/TimoBechtel) |
| 84 | + |
| 85 | +## 🤝 Contributing |
| 86 | + |
| 87 | +Contributions, issues and feature requests are welcome!<br /> |
| 88 | + |
| 89 | +1. Check [issues](https://github.com/CompactJS/random/issues) |
| 90 | +1. Fork the Project |
| 91 | +1. Create your Feature Branch (`git checkout -b feat/AmazingFeature`) |
| 92 | +1. Test your changes `npm run test` |
| 93 | +1. Commit your Changes (`git commit -m 'feat: add amazingFeature'`) |
| 94 | +1. Push to the Branch (`git push origin feat/AmazingFeature`) |
| 95 | +1. Open a Pull Request |
| 96 | + |
| 97 | +### Commit messages |
| 98 | + |
| 99 | +This project uses semantic-release for automated release versions. So commits in this project follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0-beta.2/) guidelines. I recommend using [commitizen](https://github.com/commitizen/cz-cli) for automated commit messages. |
| 100 | + |
| 101 | +## Show your support |
| 102 | + |
| 103 | +Give a ⭐️ if this project helped you! |
| 104 | + |
| 105 | +## 📝 License |
| 106 | + |
| 107 | +Distributed under the [MIT](https://github.com/CompactJS/random/blob/master/LICENSE) License. |
| 108 | + |
| 109 | +--- |
| 110 | + |
| 111 | +_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_ |
0 commit comments