From e3b12eab86b90b19cedc7f430edb2c9a5b497d3f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 9 May 2026 23:50:24 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20optimize=20random=20number?= =?UTF-8?q?=20generation=20in=20random.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implemented a hybrid sampling strategy for unique random numbers: - Use rejection sampling (Set) for sparse requests (<50% of range). - Use exclusion-based sampling (partial Fisher-Yates shuffle) for dense requests. This avoids the Coupon Collector's Problem and ensures O(count) performance. Co-authored-by: babelman97 <186798789+babelman97@users.noreply.github.com> --- .jules/bolt.md | 7 +++++++ random.html | 35 ++++++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..73fa101 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,7 @@ +## 2025-05-15 - Hybrid Sampling for Unique Random Numbers +**Learning:** Rejection sampling using a Set for unique random number generation suffers from the Coupon Collector's Problem, where performance degrades exponentially as the requested count approaches the range size due to increasing collisions. +**Action:** Implement a hybrid strategy: use rejection sampling for sparse requests (<50% of range) to save memory, and switch to an exclusion-based strategy (like a partial Fisher-Yates shuffle) for dense requests to ensure (Count)$ performance. + +## 2025-05-15 - Avoid Cold Path Micro-optimizations +**Learning:** Optimizing one-time setup functions (e.g., platform detection using regex on `navigator.userAgent`) is a micro-optimization that adds code complexity without improving the user experience or solving a real bottleneck. +**Action:** Focus on "hot paths" (high-frequency loops, frequent event handlers, or heavy data processing) where performance gains are measurable and impactful. diff --git a/random.html b/random.html index 2609ac8..a7c1ed3 100644 --- a/random.html +++ b/random.html @@ -49,22 +49,39 @@