init
This commit is contained in:
3
node_modules/knuth-shuffle-seeded/.jsdoc.conf
generated
vendored
Normal file
3
node_modules/knuth-shuffle-seeded/.jsdoc.conf
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": [ "plugins/markdown" ]
|
||||
}
|
17
node_modules/knuth-shuffle-seeded/.npmignore
generated
vendored
Normal file
17
node_modules/knuth-shuffle-seeded/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
lib-cov
|
||||
*.seed
|
||||
*.log
|
||||
*.csv
|
||||
*.dat
|
||||
*.out
|
||||
*.pid
|
||||
*.gz
|
||||
|
||||
pids
|
||||
logs
|
||||
results
|
||||
coverage
|
||||
out
|
||||
|
||||
npm-debug.log
|
||||
node_modules
|
16
node_modules/knuth-shuffle-seeded/.travis.yml
generated
vendored
Normal file
16
node_modules/knuth-shuffle-seeded/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- '0.10'
|
||||
- '0.11'
|
||||
|
||||
branches:
|
||||
only:
|
||||
- /.*/
|
||||
|
||||
script:
|
||||
- npm test
|
||||
|
||||
after_success: |
|
||||
if [ "$TRAVIS_NODE_VERSION" = '0.10' ]; then
|
||||
npm run codecov;
|
||||
fi
|
45
node_modules/knuth-shuffle-seeded/CHANGELOG.md
generated
vendored
Normal file
45
node_modules/knuth-shuffle-seeded/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
# Changelog
|
||||
|
||||
## 1.0.6: 2015-01-30
|
||||
|
||||
+ Regression tests using Mocha.
|
||||
+ Travis CI support.
|
||||
+ Codecov.io code coverage tracking support.
|
||||
+ Add a proper CHANGELOG.md.
|
||||
* Move shuffle.js to browser.js.
|
||||
|
||||
## 1.0.5: 2015-01-22
|
||||
|
||||
* Use `^` in `package.json` for support for old `npm`.
|
||||
|
||||
## 1.0.4: 2015-01-22
|
||||
|
||||
* Remove hard dependency on `node >= 0.10.0`.
|
||||
|
||||
## 1.0.3: 2015-01-22
|
||||
|
||||
* Move example.html to index.html for GitHub Pages.
|
||||
* Check if seed is undefined or null rather than checking the number of
|
||||
arguments.
|
||||
|
||||
## 1.0.2: 2015-01-19
|
||||
|
||||
* Fix order of operation.
|
||||
* Support falsy `seed` values.
|
||||
|
||||
## 1.0.1: 2015-01-19
|
||||
|
||||
* Depend on `node >= 0.10.0`.
|
||||
* Various fixes in `package.json`.
|
||||
|
||||
## 1.0.0: 2015-01-19
|
||||
|
||||
+ Proper README.
|
||||
+ Example for using this module in the browser.
|
||||
* Various fixes in `package.json`.
|
||||
* Better error reporting on input not being an Array.
|
||||
* JSDoc documentation.
|
||||
|
||||
## 0.0.0: 2015-01-19
|
||||
|
||||
+ Initial release.
|
202
node_modules/knuth-shuffle-seeded/LICENSE
generated
vendored
Normal file
202
node_modules/knuth-shuffle-seeded/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
72
node_modules/knuth-shuffle-seeded/README.md
generated
vendored
Normal file
72
node_modules/knuth-shuffle-seeded/README.md
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
# knuth-shuffle-seeded
|
||||
|
||||
[](https://www.npmjs.com/package/knuth-shuffle-seeded)
|
||||
[](https://travis-ci.org/TimothyGu/knuth-shuffle-seeded)
|
||||
[](https://david-dm.org/TimothyGu/knuth-shuffle-seeded#info=dependencies)
|
||||
[](https://david-dm.org/TimothyGu/knuth-shuffle-seeded#info=devDependencies)
|
||||
[](https://codecov.io/github/TimothyGu/knuth-shuffle-seeded?branch=gh-pages)
|
||||
|
||||
The Fisher-Yates (aka Knuth) shuffle for the browser and Node.js, with seeds
|
||||
support using [seed-random](https://www.npmjs.com/package/seed-random).
|
||||
|
||||
This project is initially forked from
|
||||
[coolaj86/knuth-shuffle](https://github.com/coolaj86/knuth-shuffle), but is
|
||||
extended so that it is possible to specify a seed to use in the shuffling, to
|
||||
ensure test reproducability.
|
||||
|
||||
Online demo: https://timothygu.github.io/knuth-shuffle-seeded/
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Node.js
|
||||
|
||||
Installing:
|
||||
|
||||
```sh
|
||||
npm install knuth-shuffle-seeded
|
||||
```
|
||||
|
||||
### The Browser
|
||||
|
||||
Put browser.js into your directory for JavaScripts. Then take a look at
|
||||
index.html.
|
||||
|
||||
You can also visit the page at
|
||||
https://timothygu.github.io/knuth-shuffle-seeded/.
|
||||
|
||||
### API
|
||||
|
||||
```js
|
||||
shuffle(inputArray[, seed])
|
||||
```
|
||||
|
||||
See example.js for more examples.
|
||||
|
||||
## Why not contribute to the original repo?
|
||||
|
||||
I have considered that, but the introduction of an npm dependency makes it
|
||||
necessary to use Browserify to generate a browser-compatible JavaScript file,
|
||||
which is too far away from the simple approach of knuth-shuffle.
|
||||
|
||||
## Authors
|
||||
|
||||
- AJ O'Neal (@coolaj86) -- initial author
|
||||
- Timothy Gu (@TimothyGu) -- seeding support
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2013 AJ O'Neal
|
||||
|
||||
Copyright 2015 Tiancheng "Timothy" Gu
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
use this project except in compliance with the License. You may obtain a copy
|
||||
of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
7
node_modules/knuth-shuffle-seeded/bower.json
generated
vendored
Normal file
7
node_modules/knuth-shuffle-seeded/bower.json
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "knuth-shuffle-seeded",
|
||||
"version": "1.0.6",
|
||||
"main": "browser.js",
|
||||
"dependencies": {},
|
||||
"devDependencies": {}
|
||||
}
|
10
node_modules/knuth-shuffle-seeded/browser.js
generated
vendored
Normal file
10
node_modules/knuth-shuffle-seeded/browser.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.shuffle=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
||||
"use strict";var randGen=require("seed-random");module.exports=function(r,n){var e,o,t,a;if(a=null==n?randGen():randGen(n),r.constructor!==Array)throw new Error("Input is not an array");for(e=r.length;0!==e;)t=Math.floor(a()*e--),o=r[e],r[e]=r[t],r[t]=o;return r};
|
||||
},{"seed-random":2}],2:[function(require,module,exports){
|
||||
(function (global){
|
||||
"use strict";function ARC4(t){var o,n=t.length,r=this,a=0,i=r.i=r.j=0,e=r.S=[];for(n||(t=[n++]);width>a;)e[a]=a++;for(a=0;width>a;a++)e[a]=e[i=mask&i+t[a%n]+(o=e[a])],e[i]=o;(r.g=function(t){for(var o,n=0,a=r.i,i=r.j,e=r.S;t--;)o=e[a=mask&a+1],n=n*width+e[mask&(e[a]=e[i=mask&i+o])+(e[i]=o)];return r.i=a,r.j=i,n})(width)}function flatten(t,o){var n,r=[],a=(typeof t)[0];if(o&&"o"==a)for(n in t)try{r.push(flatten(t[n],o-1))}catch(i){}return r.length?r:"s"==a?t:t+"\x00"}function mixkey(t,o){for(var n,r=t+"",a=0;a<r.length;)o[mask&a]=mask&(n^=19*o[mask&a])+r.charCodeAt(a++);return tostring(o)}function autoseed(t){try{return GLOBAL.crypto.getRandomValues(t=new Uint8Array(width)),tostring(t)}catch(o){return[+new Date,GLOBAL,GLOBAL.navigator&&GLOBAL.navigator.plugins,GLOBAL.screen,tostring(pool)]}}function tostring(t){return String.fromCharCode.apply(0,t)}var width=256,chunks=6,digits=52,pool=[],GLOBAL="undefined"==typeof global?window:global,startdenom=Math.pow(width,chunks),significance=Math.pow(2,digits),overflow=2*significance,mask=width-1,oldRandom=Math.random;module.exports=function(t,o){if(o&&o.global===!0)return o.global=!1,Math.random=module.exports(t,o),o.global=!0,Math.random;var n=o&&o.entropy||!1,r=[],a=(mixkey(flatten(n?[t,tostring(pool)]:0 in arguments?t:autoseed(),3),r),new ARC4(r));return mixkey(tostring(a.S),pool),function(){for(var t=a.g(chunks),o=startdenom,n=0;significance>t;)t=(t+n)*width,o*=width,n=a.g(1);for(;t>=overflow;)t/=2,o/=2,n>>>=1;return(t+n)/o}},module.exports.resetGlobal=function(){Math.random=oldRandom},mixkey(Math.random(),pool);
|
||||
|
||||
|
||||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||||
},{}]},{},[1])(1)
|
||||
});
|
37
node_modules/knuth-shuffle-seeded/example.js
generated
vendored
Normal file
37
node_modules/knuth-shuffle-seeded/example.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
// This is a demo of using knuth-shuffle-seeded with Node.js.
|
||||
|
||||
'use strict'
|
||||
|
||||
var shuffle = require('./')
|
||||
, assert = require('assert')
|
||||
, a = [ 2, 11, 37, 42 ]
|
||||
|
||||
// shuffle() modifies the original array as well.
|
||||
|
||||
// Calling a.slice(0) creates a copy, which is then assigned to b
|
||||
var copy = a.slice(0)
|
||||
var b = shuffle(copy)
|
||||
console.log(copy, b)
|
||||
|
||||
// Seed the following two functions the same way. The output should be the
|
||||
// same.
|
||||
var c = shuffle(a.slice(0), 2)
|
||||
var d = shuffle(a.slice(0), 2)
|
||||
console.log(c, d)
|
||||
|
||||
// The seed can be a string too:
|
||||
var e = shuffle(a.slice(0), 'str')
|
||||
var f = shuffle(a.slice(0), 'str')
|
||||
console.log(e, f)
|
||||
|
||||
var g = shuffle(a.slice(0), '\ns\0t\rr\uD834')
|
||||
console.log(g)
|
||||
|
||||
// It can even be an object or array, although it is not recommended to do so:
|
||||
var h = shuffle(a.slice(0), { obj: true })
|
||||
var i = shuffle(a.slice(0), new Date(0))
|
||||
var j = shuffle(a.slice(0), a)
|
||||
console.log(h, i, j)
|
||||
|
||||
// But it can't be undefined or null. If it is, then the "seed" is discarded
|
||||
// and a random one will be used.
|
104
node_modules/knuth-shuffle-seeded/index.html
generated
vendored
Normal file
104
node_modules/knuth-shuffle-seeded/index.html
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="Fisher-Yates Shuffle Demo">
|
||||
<meta name="author" content="Timothy Gu">
|
||||
|
||||
<title>Fisher-Yates Shuffle Demo</title>
|
||||
|
||||
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
|
||||
<style>
|
||||
textarea.pre {
|
||||
font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
|
||||
font-size: 1em;
|
||||
}
|
||||
</style>
|
||||
|
||||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<article class="container">
|
||||
<h1>
|
||||
Fisher-Yates Shuffle Demo
|
||||
</h1>
|
||||
<p>
|
||||
This is a demo of <strong><a href="https://github.com/TimothyGu/knuth-shuffle-seeded">knuth-shuffle-seeded</a></strong>. Enjoy!
|
||||
</p>
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label for="inputArray">Input</label>
|
||||
<textarea class="form-control pre" id="inputArray" rows="8" placeholder="Enter JSON-formatted array"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label for="seed">Seed</label>
|
||||
<input type="text" class="form-control" id="seed" placeholder="Enter seed (optional)">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-default" onclick="shuffleInput('inputArray', 'out', 'seed')">
|
||||
Submit
|
||||
</button>
|
||||
</div>
|
||||
<pre id="out"></pre>
|
||||
</div>
|
||||
</article>
|
||||
<footer class="container-fluid">
|
||||
<p class="text-center small">
|
||||
Made with ❤ by <a href="https://github.com/TimothyGu">@TimothyGu</a>. Copyright 2015. Apache License Version 2.0.
|
||||
</p>
|
||||
</footer>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
|
||||
<script src="browser.js"></script>
|
||||
<script>
|
||||
function shuffleInput (inputId, outputId, seedId) {
|
||||
var // Input array
|
||||
arr = document.getElementById(inputId)
|
||||
, // Output HTML element
|
||||
out = document.getElementById(outputId)
|
||||
, // User-specified seed
|
||||
seed = document.getElementById(seedId).value
|
||||
, // Output string
|
||||
outStr
|
||||
|
||||
// Handle errors by catching it, print the message to the output HTML
|
||||
// box, and throwing it again so that it's visible on the JS console.
|
||||
function handleError(func) {
|
||||
try {
|
||||
func()
|
||||
} catch (e) {
|
||||
out.textContent = e.stack
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
// Parse input array.
|
||||
handleError(function () {
|
||||
arr = JSON.parse(arr.value)
|
||||
})
|
||||
|
||||
// If the seed is empty, assume the user does not want to use a seed.
|
||||
if (seed === '') seed = undefined
|
||||
// If seed is a number assume the user wants to use a numerical seed.
|
||||
else if (seed == String(+seed)) seed = +seed
|
||||
|
||||
handleError(function () {
|
||||
// Shuffle the array with the seed, and stringifies it to outStr.
|
||||
outStr = JSON.stringify(shuffle(arr, seed))
|
||||
})
|
||||
|
||||
// Insert output string to the output HTML box.
|
||||
out.textContent = outStr
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
69
node_modules/knuth-shuffle-seeded/index.js
generated
vendored
Normal file
69
node_modules/knuth-shuffle-seeded/index.js
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2013 AJ O'Neal
|
||||
* Copyright 2015 Tiancheng "Timothy" Gu
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Implementation of the Fisher-Yates shuffle algorithm in JavaScript, with
|
||||
* the possibility of using a seed to ensure reproducibility.
|
||||
*
|
||||
* @module knuth-shuffle-seeded
|
||||
*/
|
||||
|
||||
var randGen = require('seed-random')
|
||||
|
||||
/**
|
||||
* Shuffle an array using the Fisher-Yates shuffle algorithm, aka Knuth
|
||||
* shuffle.
|
||||
*
|
||||
* Note that this function overwrites the initial array. As a result if you
|
||||
* would like to keep the original array intact, you have to copy the initial
|
||||
* array to a new array.
|
||||
*
|
||||
* Implementation derived from http://stackoverflow.com/questions/2450954/.
|
||||
*
|
||||
* @param {Array} array An array that is to be shuffled.
|
||||
* @param [seed=Math.random()] Seed for the shuffling operation. If
|
||||
* unspecified then a random value is used.
|
||||
* @return {Array} The resulting array.
|
||||
*/
|
||||
module.exports = function shuffle(array, seed) {
|
||||
var currentIndex
|
||||
, temporaryValue
|
||||
, randomIndex
|
||||
, rand
|
||||
if (seed == null) rand = randGen()
|
||||
else rand = randGen(seed)
|
||||
|
||||
if (array.constructor !== Array) throw new Error('Input is not an array')
|
||||
currentIndex = array.length
|
||||
|
||||
// While there remain elements to shuffle...
|
||||
while (0 !== currentIndex) {
|
||||
// Pick a remaining element...
|
||||
randomIndex = Math.floor(rand() * (currentIndex --))
|
||||
|
||||
// And swap it with the current element.
|
||||
temporaryValue = array[currentIndex]
|
||||
array[currentIndex] = array[randomIndex]
|
||||
array[randomIndex] = temporaryValue
|
||||
}
|
||||
|
||||
return array
|
||||
}
|
50
node_modules/knuth-shuffle-seeded/package.json
generated
vendored
Normal file
50
node_modules/knuth-shuffle-seeded/package.json
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "knuth-shuffle-seeded",
|
||||
"version": "1.0.6",
|
||||
"description": "The Fisher-Yates (aka Knuth) shuffle for Node.js, with seeding support",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "mocha",
|
||||
"browserify": "browserify -s shuffle -g uglifyify -o browser.js index.js",
|
||||
"prepublish": "npm run browserify",
|
||||
"coverage": "istanbul cover node_modules/mocha/bin/_mocha",
|
||||
"codecov": "npm run coverage && cat ./coverage/lcov.info | codecov"
|
||||
},
|
||||
"homepage": "https://github.com/TimothyGu/knuth-shuffle-seeded",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/TimothyGu/knuth-shuffle-seeded.git"
|
||||
},
|
||||
"keywords": [
|
||||
"ronald",
|
||||
"fisher",
|
||||
"frank",
|
||||
"yates",
|
||||
"fisher-yates",
|
||||
"donald",
|
||||
"knuth",
|
||||
"shuffle",
|
||||
"random",
|
||||
"randomize",
|
||||
"unbiased",
|
||||
"algorithm"
|
||||
],
|
||||
"author": "AJ O'Neal <coolaj86@gmail.com> (http://coolaj86.info/)",
|
||||
"contributors": [
|
||||
"Timothy Gu <timothygu99@gmail.com> (https://timothygu.github.io/)"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/TimothyGu/knuth-shuffle-seeded/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"seed-random": "~2.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify": "~8.1.1",
|
||||
"codecov.io": "~0.0.8",
|
||||
"istanbul": "~0.3.5",
|
||||
"mocha": "~2.1.0",
|
||||
"uglifyify": "~3.0.1"
|
||||
}
|
||||
}
|
119
node_modules/knuth-shuffle-seeded/test/test.js
generated
vendored
Normal file
119
node_modules/knuth-shuffle-seeded/test/test.js
generated
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
// Licensed under the Apache License, version 2.0
|
||||
|
||||
'use strict'
|
||||
|
||||
var shuffle = require('..')
|
||||
, assert = require('assert')
|
||||
, test = [ 2, 11, 37, 42, 'adsf', 'blah', { heeeheee: true } ]
|
||||
|
||||
it('changes input array', function () {
|
||||
var input = test.slice(0)
|
||||
, a = shuffle(input)
|
||||
assert.deepEqual(a, input)
|
||||
})
|
||||
|
||||
describe('random shuffling', function () {
|
||||
it('works', function () {
|
||||
var a = shuffle(test.slice(0))
|
||||
, b = shuffle(test.slice(0))
|
||||
, c = shuffle(test.slice(0))
|
||||
// Try three times.
|
||||
// The possibility of this test being a false positive is:
|
||||
//
|
||||
// / 1 \ 3 -12
|
||||
// |----| ≈ 7.81 × 10 ≈ 0.0000000078%
|
||||
// \ 7! /
|
||||
//
|
||||
// That's good enough IMO.
|
||||
try {
|
||||
assert.notDeepEqual(test, a)
|
||||
} catch (e) {
|
||||
if (!(e instanceof AssertionError)) throw e
|
||||
try {
|
||||
assert.notDeepEqual(test, b)
|
||||
} catch (e) {
|
||||
if (!(e instanceof AssertionError)) throw e
|
||||
assert.notDeepEqual(test, c)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('seeding with a number', function () {
|
||||
var a, b
|
||||
|
||||
it('does not crash', function () {
|
||||
a = shuffle(test.slice(0), 2)
|
||||
b = shuffle(test.slice(0), 2)
|
||||
})
|
||||
|
||||
it('output is the same for the same seed', function () {
|
||||
assert.deepEqual(a, b)
|
||||
assert.deepEqual(a, [ 'blah', { heeeheee: true }, 2, 'adsf', 11, 42, 37 ])
|
||||
})
|
||||
})
|
||||
|
||||
describe('seeding with a object', function () {
|
||||
var obj1 = { blah: 'ad', bla: 4 }
|
||||
, obj2 = new Date()
|
||||
, a
|
||||
, b
|
||||
|
||||
it('does not crash', function () {
|
||||
a = shuffle(test.slice(0), obj1)
|
||||
b = shuffle(test.slice(0), obj2)
|
||||
})
|
||||
})
|
||||
|
||||
describe('seeding with a string', function () {
|
||||
var str = 'Lorem ipsum'
|
||||
, a
|
||||
, b
|
||||
|
||||
it('does not crash', function () {
|
||||
a = shuffle(test.slice(0), str)
|
||||
b = shuffle(test.slice(0), str)
|
||||
})
|
||||
|
||||
it('output is the same for the same seed', function () {
|
||||
assert.deepEqual(a, b)
|
||||
assert.deepEqual(a, [ { heeeheee: true }, 2, 'blah', 11, 'adsf', 42, 37 ])
|
||||
})
|
||||
})
|
||||
|
||||
describe('errors', function () {
|
||||
it('on String input', function () {
|
||||
assert.throws(function () {
|
||||
shuffle('adf')
|
||||
})
|
||||
})
|
||||
it('on Boolean input', function () {
|
||||
assert.throws(function () {
|
||||
shuffle(true)
|
||||
})
|
||||
})
|
||||
it('on Object input', function () {
|
||||
assert.throws(function () {
|
||||
shuffle({ a: true })
|
||||
})
|
||||
})
|
||||
it('on Number input', function () {
|
||||
assert.throws(function () {
|
||||
shuffle(40)
|
||||
})
|
||||
})
|
||||
it('on null input', function () {
|
||||
assert.throws(function () {
|
||||
shuffle(null)
|
||||
})
|
||||
})
|
||||
it('on undefined input', function () {
|
||||
assert.throws(function () {
|
||||
shuffle(undefined)
|
||||
})
|
||||
})
|
||||
it('not on empty array', function () {
|
||||
var a = shuffle([])
|
||||
assert.deepEqual(a, [])
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user