Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8062543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:42:21+00:00 2026-06-05T10:42:21+00:00

Problem I have N items of various types evenly distributed into their own buckets

  • 0

Problem

I have N items of various types evenly distributed into their own buckets determined by type. I want to create a new list that:

  1. randomly picks from each bucket
  2. does not pick from the same bucket twice in a row
  3. each bucket must have (if possible) an equal amount of representation in the final list
  4. not using language specific libraries (not easily implemented in another language)

Example

I have 12 items of 4 distinct types which means I have 4 buckets:

Bucket A - [a, a, a]
Bucket B - [b, b, b]
Bucket C - [c, c, c]
Bucket D - [d, d, d]

What I want

A list of the above items in a random distribution without any characters repeating with a size between 1 and N.

12 Items: a, d, c, a, b, a, c, d, c, b, d, b

8 Items: c, a, d, a, b, d, c, b

4 Items: c, b, d, a

3 Items: b, c, a (Skipping D)

I was trying to do this with a while loop that generates random integers until the next bucket isn’t equal to the previously used bucket, but that seems inefficient, and was hoping someone else might have a better algorithm to solve this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:42:22+00:00Added an answer on June 5, 2026 at 10:42 am

    You could generate a random list of the buckets, and then randomly pick from then in order, removing the bucket from the list when you pick from it. When the list is empty, regenerate a random list of buckets, repeating until you pick the desired number of items.

    Can you repeat items from the buckets? So if you pick the 1st “a” from bucket A the first time around, can you pick it a 2nd time? That’ll change the solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the problem: I have a list of items with various length for
I have a annoying problem .. I want my first 4 items in a
I have a problem with sorting items in table in PHP. Here is what
so I have a problem with dynamically adding items to menuStrip. I mean I
I have a small problem where I want to find the next active item
I have the following problem. I want to check that the item clicked on
I have jQuery in various files, and recently I have needed to change items
I have a number of Python generators, which I want to combine into a
Problem I have various html tables that I need to parse/access from my customers
Here's the problem: I have a data-bound list of items, basically a way for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.