diff --git a/scripts/README.md b/scripts/README.md
new file mode 100644
index 0000000..bcaac89
--- /dev/null
+++ b/scripts/README.md
@@ -0,0 +1,48 @@
+# Branch Coverage Measurement
+
+This directory contains scripts for measuring branch coverage of the random simulation.
+
+## Prerequisites
+
+The HTML report generation requires `lcov`:
+
+```bash
+sudo apt-get install lcov
+```
+
+## Usage
+
+### Quick text summary (5 second simulation)
+```bash
+make coverage-report
+```
+
+### HTML report with branch details (5 second simulation)
+```bash
+make coverage-html
+```
+
+### Custom duration
+```bash
+./scripts/measure_coverage.sh 10 # 10 second run, text output
+./scripts/measure_coverage.sh 10 --html # 10 second run, HTML output
+```
+
+## What gets measured
+
+The coverage tool:
+- Builds the test binary with coverage instrumentation (`--coverage` flag)
+- Runs the random simulation for the specified duration
+- Generates reports showing which branches were executed
+
+## Output
+
+**Text report**: Shows per-file and total branch coverage percentages
+
+**HTML report**: Interactive report generated by lcov/genhtml showing:
+- Overall coverage summary
+- Per-file coverage breakdown
+- Source code with execution counts
+- Branch coverage details
+
+The HTML report is generated in `coverage_report/index.html`
diff --git a/scripts/generate_coverage_html.sh b/scripts/generate_coverage_html.sh
index 04a8c33..c29788b 100755
--- a/scripts/generate_coverage_html.sh
+++ b/scripts/generate_coverage_html.sh
@@ -1,164 +1,31 @@
#!/bin/bash
-# Generate HTML coverage report from gcov files
+# Generate HTML coverage report using lcov
set -e
OUTPUT_DIR="coverage_report"
-mkdir -p "$OUTPUT_DIR"
-# Create main index.html
-cat > "$OUTPUT_DIR/index.html" <<'HTMLHEADER'
-
-
-
-
- Branch Coverage Report
-
-
- Branch Coverage Report
- Generated from random simulation coverage analysis
-
- Overall Coverage Summary
-HTMLHEADER
-
-# Calculate totals
-TOTAL_BRANCHES=0
-TAKEN_BRANCHES=0
-
-for gcov_file in *.c.gcov; do
- if [ -f "$gcov_file" ]; then
- branches=$(grep -c "^branch" "$gcov_file" 2>/dev/null || echo "0")
- if [ "$branches" -gt 0 ]; then
- taken=$(grep "^branch" "$gcov_file" 2>/dev/null | grep -c "taken [1-9]" 2>/dev/null || echo "0")
- taken=$(echo "$taken" | tr -d '[:space:]')
- if [ -z "$taken" ]; then taken=0; fi
-
- TOTAL_BRANCHES=$((TOTAL_BRANCHES + branches))
- TAKEN_BRANCHES=$((TAKEN_BRANCHES + taken))
- fi
- fi
-done
-
-if [ "$TOTAL_BRANCHES" -gt 0 ]; then
- COVERAGE_PERCENT=$((TAKEN_BRANCHES * 100 / TOTAL_BRANCHES))
-
- cat >> "$OUTPUT_DIR/index.html" <
- Total Branches: $TOTAL_BRANCHES
- Branches Taken: $TAKEN_BRANCHES
- Coverage: ${COVERAGE_PERCENT}%
-
-
- Coverage by File
-
-
- | File |
- Branches Taken |
- Total Branches |
- Coverage % |
-
-HTMLSUMMARY
-
- # Generate table rows for each file
- for gcov_file in *.c.gcov; do
- if [ -f "$gcov_file" ]; then
- filename=$(echo "$gcov_file" | sed 's/.gcov$//')
- branches=$(grep -c "^branch" "$gcov_file" 2>/dev/null || echo "0")
-
- if [ "$branches" -gt 0 ]; then
- taken=$(grep "^branch" "$gcov_file" 2>/dev/null | grep -c "taken [1-9]" 2>/dev/null || echo "0")
- taken=$(echo "$taken" | tr -d '[:space:]')
- if [ -z "$taken" ]; then taken=0; fi
-
- percentage=$((taken * 100 / branches))
-
- # Generate individual file report
- file_html="${filename}.html"
- echo "Generating report for $filename..."
-
- cat > "$OUTPUT_DIR/$file_html" <
-
-
-
- Coverage: $filename
-
-
- Back to Summary
- Coverage: $filename
- Branches Taken: $taken / $branches ($percentage%)
-
-FILEHEADER
-
- # Process the gcov file and add source code with branch info
- awk '
- /^branch/ {
- branch_info = branch_info " " $0
- next
- }
- /^ / {
- # Line with execution count
- line_num = $2
- gsub(/:/, "", line_num)
- exec_count = $1
- gsub(/^[ \t]+/, "", exec_count)
-
- # Get the actual source line
- line_content = substr($0, index($0, $3))
-
- # Format execution count
- if (exec_count == "-") {
- exec_str = "-"
- } else if (exec_count == "#####") {
- exec_str = "0"
- } else {
- exec_str = exec_count
- }
-
- # Output line number, execution count, and source
- printf "%6s: %5s:%s", line_num, exec_str, line_content
-
- if (branch_info != "") {
- printf " [%s]", branch_info
- }
- printf "\n"
-
- branch_info = ""
- }
- ' "$gcov_file" >> "$OUTPUT_DIR/$file_html"
-
- cat >> "$OUTPUT_DIR/$file_html" <<'FILEFOOTER'
-
-
-
-FILEFOOTER
-
- # Add row to main index
- cat >> "$OUTPUT_DIR/index.html" <
- $filename |
- $taken |
- $branches |
- ${percentage}% |
-
-TABLEROW
- fi
- fi
- done
-
- # Close HTML
- cat >> "$OUTPUT_DIR/index.html" <<'HTMLFOOTER'
-
-
-
-HTMLFOOTER
-
-else
- cat >> "$OUTPUT_DIR/index.html" <<'HTMLFOOTER'
- No branch coverage data found.
-