summaryrefslogtreecommitdiff
path: root/Homework/cs3460/gameoflife/PatternRandom.cpp
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2026-07-02 11:55:17 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2026-07-02 11:55:17 -0700
commit6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6 (patch)
treeed97e39ec77c5231ffd2c394493e68d00ddac5a4 /Homework/cs3460/gameoflife/PatternRandom.cpp
downloadmisc-undergrad-main.tar.gz
misc-undergrad-main.zip
Diffstat (limited to 'Homework/cs3460/gameoflife/PatternRandom.cpp')
-rw-r--r--Homework/cs3460/gameoflife/PatternRandom.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/Homework/cs3460/gameoflife/PatternRandom.cpp b/Homework/cs3460/gameoflife/PatternRandom.cpp
new file mode 100644
index 0000000..924fb2c
--- /dev/null
+++ b/Homework/cs3460/gameoflife/PatternRandom.cpp
@@ -0,0 +1,18 @@
+#include "PatternRandom.hpp"
+
+const float DISTRIBUTION_DEV = 2.0;
+
+PatternRandom::PatternRandom(std::uint8_t cols, std::uint8_t rows, float density) :
+ PatternSet(cols, rows),
+ m_distributionX(cols / 2.0, cols / DISTRIBUTION_DEV),
+ m_distributionY(rows / 2.0, rows / DISTRIBUTION_DEV)
+{
+ std::uint32_t numCellsApprox = static_cast<std::uint32_t>(density * cols * rows);
+
+ for (std::uint32_t i = 0; i < numCellsApprox; ++i)
+ {
+ std::uint8_t randX = std::clamp(static_cast<std::uint8_t>(m_distributionX(m_generator)), static_cast<std::uint8_t>(0), cols);
+ std::uint8_t randY = std::clamp(static_cast<std::uint8_t>(m_distributionY(m_generator)), static_cast<std::uint8_t>(0), rows);
+ m_aliveCells.insert(std::pair<std::uint8_t, std::uint8_t>(randX, randY));
+ }
+}