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/browser.md | |
download | langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.gz langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.bz2 langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.zip |
Commit
Diffstat (limited to 'src/node_modules/chance/docs/usage/browser.md')
-rw-r--r-- | src/node_modules/chance/docs/usage/browser.md | 58 |
1 files changed, 58 insertions, 0 deletions
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 |