Interactive Randomness Lab web app — commit–reveal draws and frequency / chi-square testing — with a short landing page styled after The Randomness Dossier research report.
- Frontend: Next.js (App Router) + TypeScript + TailwindCSS (
apps/web) - Backend: FastAPI + shared services (
backend) - MCP: same services exposed as MCP tools (
backend/app/mcp_server.py) - Package manager: pnpm workspaces
- Tests: pytest (business logic), Playwright (core user journeys)
- Node.js 20+
- pnpm 9+
- Python 3.11+
If pnpm install fails with TLS / certificate errors (common on corporate networks), this repo includes .npmrc with strict-ssl=false. You can also set NODE_TLS_REJECT_UNAUTHORIZED=0 for the install session.
# Install frontend + e2e deps
pnpm install
# Playwright browser (once)
pnpm --filter e2e exec playwright install chromium
# Backend virtualenv
cd backend
python -m venv .venv
# Windows:
.venv\Scripts\activate
# macOS/Linux:
# source .venv/bin/activate
pip install -e ".[dev]"
cd ..Terminal 1 — API (default http://127.0.0.1:8000):
cd backend
.venv\Scripts\activate # or source .venv/bin/activate
uvicorn app.main:app --reload --port 8000Terminal 2 — web (default http://localhost:3000):
pnpm devSet NEXT_PUBLIC_API_URL=http://127.0.0.1:8000 in apps/web/.env.local if needed (defaults to that URL).
The Lab can load Ultra Lotto 6/58 via the Google Sheets API and run the chi-square tester on real draw combinations.
- In Google Cloud Console: create/select a project → enable Google Sheets API → Credentials → API key.
- Share the spreadsheet as Anyone with the link (Viewer).
- Copy
backend/.env.exampletobackend/.envand set:
GOOGLE_SHEETS_API_KEY=your_key_here- Restart uvicorn, open
/lab, and click Load from Google Sheets.
Endpoint: POST /api/stats/from-sheet
MCP tool: analyze_lotto_sheet
Must run from the backend folder with the project venv (not system Python from the repo root):
cd backend
.\.venv\Scripts\Activate.ps1
python -m app.mcp_serverOr without activating:
cd backend
.\.venv\Scripts\python.exe -m app.mcp_serverTools: commit_draw, reveal_draw, run_frequency_test, health.
PowerShell (this repo’s default shell) — use ; instead of &&:
# Unit tests (business logic)
cd backend
.\.venv\Scripts\Activate.ps1
pytest
cd ..
# E2E (starts API + Next.js via Playwright webServer)
pnpm e2eOne-liner from repo root:
cd backend; .\.venv\Scripts\python.exe -m pytest; cd ..Target project: random-numbers-504204 (region asia-southeast1).
Prerequisites:
gcloudinstalled and logged in- Billing linked to the project (Cloud Run / Cloud Build / Artifact Registry require it)
- On Windows with Avast HTTPS scanning, use the helper below (Python 3.11 + Avast CA)
# From repo root — builds & deploys API + web
.\scripts\deploy-cloud-run.ps1This deploys:
randomness-apifrombackend/(setsGOOGLE_SHEETS_*frombackend/.env)randomness-webfromapps/web/withNEXT_PUBLIC_API_URLpointed at the API URL
Manual gcloud env fix (if SSL fails):
. .\scripts\gcloud-env.ps1
gcloud config set project random-numbers-504204apps/web/ Next.js UI
backend/ FastAPI + MCP + pytest
e2e/ Playwright
scripts/ Cloud Run deploy helpers