aboutsummaryrefslogtreecommitdiff
path: root/src/cosmic-cargo/static/random.js
diff options
context:
space:
mode:
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