diff options
author | Minteck <contact@minteck.org> | 2021-12-21 16:52:28 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2021-12-21 16:52:28 +0100 |
commit | 46e43f4bde4a35785b4997b81e86cd19f046b69b (patch) | |
tree | c53c2f826f777f9d6b2d249dab556feb72a6c3a6 /src/node_modules/chance/docs/usage | |
download | langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.gz langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.bz2 langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.zip |
Commit
Diffstat (limited to 'src/node_modules/chance/docs/usage')
-rw-r--r-- | src/node_modules/chance/docs/usage/bower.md | 19 | ||||
-rw-r--r-- | src/node_modules/chance/docs/usage/browser.md | 58 | ||||
-rw-r--r-- | src/node_modules/chance/docs/usage/cli.md | 19 | ||||
-rw-r--r-- | src/node_modules/chance/docs/usage/function.md | 22 | ||||
-rw-r--r-- | src/node_modules/chance/docs/usage/node.md | 31 | ||||
-rw-r--r-- | src/node_modules/chance/docs/usage/requirejs.md | 13 | ||||
-rw-r--r-- | src/node_modules/chance/docs/usage/seed.md | 49 |
7 files changed, 211 insertions, 0 deletions
diff --git a/src/node_modules/chance/docs/usage/bower.md b/src/node_modules/chance/docs/usage/bower.md new file mode 100644 index 0000000..41b85d4 --- /dev/null +++ b/src/node_modules/chance/docs/usage/bower.md @@ -0,0 +1,19 @@ +# bower + +Chance can be easily installed with [Bower](https://bower.io) + +```bash +bower install chance +``` + +then in the HTML of your app: + +```html +<!-- Load Chance --> +<script type="text/javascript" src="bower_components/chance/chance.js"></script> +<script> + // Use Chance + alert(chance.string()); +</script> +``` + diff --git a/src/node_modules/chance/docs/usage/browser.md b/src/node_modules/chance/docs/usage/browser.md new file mode 100644 index 0000000..54c772c --- /dev/null +++ b/src/node_modules/chance/docs/usage/browser.md @@ -0,0 +1,58 @@ +# browser + +#### Easy + +**Chance** instantiates itself onto the window. This means that in the simplest +case you can just include the script tag then use an instance of **Chance** +immediately. + +```html +<script src="chance.js"></script> +<script> + console.log(chance.bool()); +</script> +``` + +The above snippet would result in either true or false being logged to your +console. Note how the instance is lowercase *chance*. Uppercase *Chance* is the +constructor which will create a new instance of **Chance**. + +#### Intermediate + +You can also ignore the global instantiation of **Chance** and create your own. +This allows you to create multiple instances if you'd like. For convenience, we +also bind **Chance** to window so it's accessible globally in the browser at +*window.Chance* or just *Chance*. + +```html +<script src="chance.js"></script> +<script> + var my_chance = new Chance(); + console.log(my_chance.bool()); +</script> +``` + + +#### Advanced + +If you create your own instance of **Chance**, you can provide your own seed if +you would like to be repeatable or if you'd like a more truly random seed. In +the below example, I am doing an AJAX call to hit [Random.org][random] to +retrieve a *true* random number which I use to seed Chance. + +```html +<script src="http://chancejs.com/chance.min.js"></script> +<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> +<script> + var mySeed; + $.get("https://www.random.org/integers/", {num: "1", col: "1", min: "1", max: "1000000000", base: "10", format: "plain", rnd: "new"}, function(randNum) { + mySeed = randNum; + + // Instantiate Chance with this truly random number as the seed + var my_seeded_chance = new Chance(mySeed); + console.log(my_seeded_chance.natural()); + }); +</script> +``` + +[random]: http://www.random.org diff --git a/src/node_modules/chance/docs/usage/cli.md b/src/node_modules/chance/docs/usage/cli.md new file mode 100644 index 0000000..7f67262 --- /dev/null +++ b/src/node_modules/chance/docs/usage/cli.md @@ -0,0 +1,19 @@ +# cli + +To use Chance from the command line, install `chance-cli` globally with: + +```bash +npm install -g chance-cli +``` + +Then invoke any generator by name followed by options, like so: + +```bash +$ chance name --prefix true +Dr. Georgia Sanchez + +$ chance latitude --min 12.34 --max 56.78 +22.01836 +``` + +More details in the [chance-cli README](https://github.com/chancejs/chance-cli) diff --git a/src/node_modules/chance/docs/usage/function.md b/src/node_modules/chance/docs/usage/function.md new file mode 100644 index 0000000..a79ccde --- /dev/null +++ b/src/node_modules/chance/docs/usage/function.md @@ -0,0 +1,22 @@ +# function + +Instead of providing a seed, which will be used to seed our [Mersenne Twister](https://en.wikipedia.org/wiki/Mersenne_twister), +you can also specify an arbitrary function to generate random numbers which the +rest of the library will utilize when generating everything else. + +A rather simple example, simply using Math.random() instead of our Mersenne Twister + +```js +// Use Math.random() instead of our Mersenne Twister +var chance = new Chance(Math.random); + +chance.address() +=> '131 Asmun Pike' +chance.address() +=> '261 Pawnaf Highway' +``` + +Chance will appear to work just the same, but have a different underlying random +generator. + +This function should return any number between 0 and 1. diff --git a/src/node_modules/chance/docs/usage/node.md b/src/node_modules/chance/docs/usage/node.md new file mode 100644 index 0000000..914fe87 --- /dev/null +++ b/src/node_modules/chance/docs/usage/node.md @@ -0,0 +1,31 @@ +# node + +It can also be used in [Node.js](http://nodejs.org) + +```bash +npm install chance +``` + +then in your app + +```js +// Load Chance +var Chance = require('chance'); + +// Instantiate Chance so it can be used +var chance = new Chance(); + +// Use Chance here. +var my_random_string = chance.string(); +``` + +As of version 0.5.5, the following is also offered as a convenience for getting +an instance of Chance + +```js +// Load and instantiate Chance +var chance = require('chance').Chance(); + +// Use Chance here. +var my_random_string = chance.string(); +``` diff --git a/src/node_modules/chance/docs/usage/requirejs.md b/src/node_modules/chance/docs/usage/requirejs.md new file mode 100644 index 0000000..212e53c --- /dev/null +++ b/src/node_modules/chance/docs/usage/requirejs.md @@ -0,0 +1,13 @@ +# requirejs + +Load Chance with <a href="http://requirejs.org">RequireJS</a> + +```js + require(['Chance'], function(Chance) { + // Instantiate + var chance = new Chance(); + + // Then use it: + var my_random_integer = chance.integer(); + }); +``` diff --git a/src/node_modules/chance/docs/usage/seed.md b/src/node_modules/chance/docs/usage/seed.md new file mode 100644 index 0000000..737a91d --- /dev/null +++ b/src/node_modules/chance/docs/usage/seed.md @@ -0,0 +1,49 @@ +# seed + +You can also instantiate your own instance of Chance with a known seed. This is +useful for creating repeatable results. + +```js +var chance1 = new Chance(12345); +var chance2 = new Chance(12345); + +// These yield the same values, in sequence +console.log(chance1.random()); +console.log(chance2.random()); +``` + +Since both copies of Chance had the same seed, they will both generate the same +random number sequence each time they're called. + +This allows for repeatability, if desired. + +This is possible because **Chance** is built atop a [Mersenne Twister][mersenne], +a pseudo-random number generator which produces repeatable results given the same seed. + +Optionally provide the seed as a string. + +```js +var chance1 = new Chance("foo"); +var chance2 = new Chance("bar"); + +// These will be different +console.log(chance1.random()); +console.log(chance2.random()); +``` + +Optionally provide multiple arguments as the seed. + +```js +var chance1 = new Chance("hold", "me", "closer"); +var chance2 = new Chance("tony", "danza"); +var chance3 = new Chance("hold", "me", "closer"); + +// These will be different +console.log(chance1.random()); +console.log(chance2.random()); + +// This will be the same as the value from chance1 above +console.log(chance3.random()); +``` + +[mersenne]: http://en.wikipedia.org/wiki/Mersenne_twister |