From 6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6 Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Thu, 2 Jul 2026 11:55:17 -0700 Subject: Init --- Homework/cs3460/gameoflife/PatternRandom.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Homework/cs3460/gameoflife/PatternRandom.cpp (limited to 'Homework/cs3460/gameoflife/PatternRandom.cpp') 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(density * cols * rows); + + for (std::uint32_t i = 0; i < numCellsApprox; ++i) + { + std::uint8_t randX = std::clamp(static_cast(m_distributionX(m_generator)), static_cast(0), cols); + std::uint8_t randY = std::clamp(static_cast(m_distributionY(m_generator)), static_cast(0), rows); + m_aliveCells.insert(std::pair(randX, randY)); + } +} -- cgit v1.3