From ecd8d064a370ce0b9d4a353f6151638b60838208 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Fri, 17 Apr 2020 22:56:57 -0500 Subject: Add cosmic cargo --- src/cosmic-cargo/static/random.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/cosmic-cargo/static/random.js (limited to 'src/cosmic-cargo/static/random.js') 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 -- cgit v1.2.3