aboutsummaryrefslogtreecommitdiff
path: root/bin/rand.rb
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2026-03-05 18:49:02 +0100
committerMiquel Sabaté Solà <mssola@mssola.com>2026-03-05 18:49:02 +0100
commit0de830d9ac786fbbf32e9abebf3975e909b1a5e7 (patch)
tree8a5d1ad9ec7aacb29de5a2cde3524bdd22e577a7 /bin/rand.rb
parent95dee49559d78a3d1c458ad98c277ef7dbee473e (diff)
downloadjetpac.nes-0de830d9ac786fbbf32e9abebf3975e909b1a5e7.tar.gz
jetpac.nes-0de830d9ac786fbbf32e9abebf3975e909b1a5e7.zip
Make randomness a bit more random
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'bin/rand.rb')
-rw-r--r--bin/rand.rb5
1 files changed, 4 insertions, 1 deletions
diff --git a/bin/rand.rb b/bin/rand.rb
index a3e7e41..345cb4d 100644
--- a/bin/rand.rb
+++ b/bin/rand.rb
@@ -18,10 +18,13 @@ GROUND_Y_COORD = 0xC8 - 64
# The available values for the Y axis for enemies are above ground, below the
# sky, and avoiding the left-most and right-most platforms.
available = (UPPER_MARGIN_Y_COORD..GROUND_Y_COORD).to_a - (0x58..0x69).to_a - (0x40..0x50).to_a
+available = available.shuffle
# With this produce the array containing a randomized sample from the
# 'available' values.
-random_byte_array = Array.new(256) { format('$%02X', available.sample) }
+random_byte_array = (0...256).map do |i|
+ format('$%02X', available[i % available.length])
+end
# And now print it in the assembler format.
random_byte_array.each_slice(16) do |row|