aboutsummaryrefslogtreecommitdiff
path: root/src/cosmic-cargo/static/random.js
diff options
context:
space:
mode:
authorMark Powers <markppowers0@gmail.com>2020-04-17 22:56:57 -0500
committerMark Powers <markppowers0@gmail.com>2020-04-17 22:56:57 -0500
commitecd8d064a370ce0b9d4a353f6151638b60838208 (patch)
treee339598839261d8caca078d75b4327f3b034b1f7 /src/cosmic-cargo/static/random.js
parent84dca4c6dc0cff9a417ebd0d8f7de06acafa6725 (diff)
Add cosmic cargo
Diffstat (limited to 'src/cosmic-cargo/static/random.js')
-rw-r--r--src/cosmic-cargo/static/random.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/cosmic-cargo/static/random.js b/src/cosmic-cargo/static/random.js
new file mode 100644
index 0000000..152db0a
--- /dev/null
+++ b/src/cosmic-cargo/static/random.js
@@ -0,0 +1,18 @@
+function random_choice(arr){
+ return arr[random_int(arr.length)];
+}
+
+function random_int(max) {
+ return Math.floor(Math.random() * max);
+}
+
+function random_chance(percentage_of_success){
+ return Math.random() < percentage_of_success;
+}
+
+function shuffle_array(array) {
+ for (let i = array.length - 1; i > 0; i--) {
+ const j = random_int(i + 1);
+ [array[i], array[j]] = [array[j], array[i]];
+ }
+} \ No newline at end of file