⚡ Bolt: Optimize unique random number generation#60
Conversation
Implemented a hybrid sampling strategy in random.html to solve the "Coupon Collector's Problem" when generating a high density of unique random numbers. For requests where the count is >50% of the range, the algorithm now uses exclusion-based sampling followed by a Fisher-Yates shuffle, avoiding the exponential collision penalty of rejection sampling. Impact: ~12.4x speedup for 999,990 numbers in a 1,000,000 range (~3.3s down to ~0.26s). Co-authored-by: babelman97 <186798789+babelman97@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What: Optimized the unique random number generator in
random.htmlby replacing the simple rejection sampling with a hybrid strategy. It now uses exclusion-based sampling (picking numbers NOT to include) for dense requests (>50% of range).🎯 Why: The original implementation suffered from the "Coupon Collector's Problem," where finding the last few unique numbers in a nearly full set would take an exponentially increasing number of trials, causing significant UI hangs for large, dense requests.
📊 Impact:
🔬 Measurement: Benchmarked using Playwright by measuring
performance.now()around thegenerateRandomNumbers()call for both sparse (1,000/100,000) and dense (999,990/1,000,000) scenarios. Correctness was verified by ensuring the output contained the exact count of unique numbers within the requested range.PR created automatically by Jules for task 2180869317366178159 started by @babelman97