Skip to content

⚡ Bolt: Optimize unique random number generation#60

Open
babelman97 wants to merge 1 commit into
mainfrom
bolt-random-sampling-optimization-2180869317366178159
Open

⚡ Bolt: Optimize unique random number generation#60
babelman97 wants to merge 1 commit into
mainfrom
bolt-random-sampling-optimization-2180869317366178159

Conversation

@babelman97
Copy link
Copy Markdown
Owner

💡 What: Optimized the unique random number generator in random.html by 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:

  • High-density requests (e.g., 999,990 unique numbers out of 1,000,000) are now ~12.4x faster (~3,305ms reduced to ~266ms).
  • UI responsiveness is improved for large datasets with the addition of a scrollable results container.

🔬 Measurement: Benchmarked using Playwright by measuring performance.now() around the generateRandomNumbers() 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

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>
@google-labs-jules
Copy link
Copy Markdown

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant