From c5f412602832ae1b772faa8b92082992de90b3bb Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 14 Jun 2026 21:30:50 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20optimize=20random=20samplin?= =?UTF-8?q?g=20performance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement hybrid sampling in random.html: - Use rejection sampling (Set) for low density (< 50%) - Use Sparse Fisher-Yates (Map) for high density (>= 50%) - Fix range validation bug and add 10M range safety limit - Improve UI responsiveness for large result sets with CSS scroll and textContent Co-authored-by: babelman97 <186798789+babelman97@users.noreply.github.com> --- .jules/bolt.md | 3 ++ random.html | 136 ++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 122 insertions(+), 17 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..c2d8d7b --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2025-06-14 - Optimized High-Density Random Sampling in random.html +**Learning:** Rejection sampling with `Set` collapses at high density due to the Coupon Collector's Problem (probabilistic collision). While a standard Fisher-Yates shuffle on a full range `Array` provides O(N) performance, it is memory-intensive for large ranges. A **Sparse Fisher-Yates** implementation using a `Map` to track swaps in a virtual array provides guaranteed O(count) time and space complexity without large array allocation overhead. +**Action:** Use a hybrid sampling strategy (Rejection Sampling for <50% density, Sparse Fisher-Yates for >=50% density) for unique random selection to ensure optimal performance across all use cases. diff --git a/random.html b/random.html index 2609ac8..35cdea2 100644 --- a/random.html +++ b/random.html @@ -10,9 +10,11 @@ flex-direction: column; align-items: center; justify-content: center; - height: 100vh; + min-height: 100vh; background-color: #f0f0f0; font-family: Arial, sans-serif; + padding: 20px; + box-sizing: border-box; } .button { padding: 20px 40px; @@ -23,48 +25,148 @@ background-color: #4CAF50; color: white; border-radius: 10px; + transition: background-color 0.3s; + } + .button:hover { + background-color: #45a049; + } + .button:active { + transform: scale(0.98); } .number { - font-size: 36px; + font-size: 24px; color: #333; - margin-top: 10px; + margin-top: 20px; + max-height: 50vh; + overflow-y: auto; + word-wrap: break-word; + background: white; + padding: 15px; + border-radius: 10px; + box-shadow: 0 2px 5px rgba(0,0,0,0.1); + width: 90%; + max-width: 800px; + text-align: center; } .input-field { margin: 10px 0; font-size: 18px; padding: 10px; - width: 80px; + width: 120px; text-align: center; border: 1px solid #ccc; border-radius: 5px; } + .input-group { + display: flex; + align-items: center; + gap: 10px; + margin: 5px 0; + } + .input-label { + min-width: 80px; + text-align: right; + } -
最小數字 
-
最大數字 
-
隨機個數 
+
+ 最小數字 + +
+
+ 最大數字 + +
+
+ 隨機個數 + +