Tools for generating different types of random behaviour in Javascript.
You can use Chancer on the server side with Node.js and npm:
npm install chancer
On the client side, you can include Chancer in your page (found in build/chancer.js):
<script src="chancer.js"></script>
In Node.js you can include Chancer in your script by using require:
var chancer = require('chancer');
If you're including via a <script>
tag, chancer
is available as a global variable.
Generates a floating-point number between 0 and 1
return: (float) Returns the floating point number
chancer.random(); // 0.32831766246818006
Generates a floating-point number between min (inclusive) and max (exclusive)
min: (float) Minimum inclusive number
max: (float) Maximum exclusive number
return: (float) Returns the floating point number
chancer.float(1, 10); // 2.794354454614222
Generates an integer between min (inclusive) and max (inclusive)
min: (float) Minimum inclusive number
max: (float) Maximum inclusive number
return: (integer) Returns the integer number
chancer.int(1, 10); // 3
Tested in the following browsers
Chrome | Opera | Firefox | Safari | IE | iOS | Android | WindowsPhone |
---|---|---|---|---|---|---|---|
3+ | 2.2+ | 8.1+ |
Chancer is licensed under the MIT license.
Copyright © 2015, Alex Kilgour