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 3460652
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:15:21+00:00 2026-05-18T10:15:21+00:00

If the number range is 0 – 10. I would like to generate the

  • 0
If the number range is 0 - 10. I would like to generate the following numbers

e.g. 

unique 5 numbers [3, 8, 5, 1, 9]
unique 3 numbers [2, 6, 5]
5 numbers of which 2 numbers occur twice [2, 3, 2, 6, 3]
7 numbers of which 2 numbers occur twice [2, 5, 9, 2, 7, 5, 3] (Here 2, 5 occur twice)
5 numbers of which 1 number occur thrice [2, 3, 8, 3, 3] (Here 3 occurs twice)
7 numbers of which 1 number occur thrice and 1 number occurs twice [1, 5, 9, 1, 1, 5, 3] (Here 1 occurs thrice, 5 occurs twice)

How would you implement a generic function which caters to the above requirements.

EDIT1:

This is what I have right now..

protected List<Integer> fetchOverlapIntegers(int min, int max,
        int howMany, int overlap) {
    // The following code fetches unique numbers within the range
    List<Integer> numbers = this.fetchRandomIntegers(min, max, howMany);

    if (overlap > 0) {
        int size = numbers.size();
        for (int i = 0; i < overlap; i++) {
            numbers.set(size - 1 - i, numbers.get(i));
        }
    }
    Collections.shuffle(numbers);

    return numbers;
}
  • 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-05-18T10:15:21+00:00Added an answer on May 18, 2026 at 10:15 am

    Just for grins I wrote this up for this very underspecified problem:

    public static List<Integer> weirdFunction(List<Integer> criteria, List<Integer> candidateNumbers) {
        List<Integer> results = new ArrayList<Integer>();    
        for (int occurrenceCount = 0; occurrenceCount < criteria.size(); occurrenceCount++) {
            int thisMany = criteria.get(occurrenceCount);
            for (int i=0; i < thisMany; i++) {
                Integer theChoice = candidateNumbers.get(new Random().nextInt(candidateNumbers.size()));
                for (int ct=0; ct < occurrenceCount; ct++) {
                    results.add(theChoice);
                }
            }
        }
        Collections.shuffle(results);
        return results;
    }
    

    It takes two lists, one which is the criteria which is basically a list of how many times it’ll place a randomly chosen number in the results (the 1st one gets chosen once, the 2nd twice, etc.), and a list of candidateNumbers from which they’ll be chosen.

    But, this way only allows you to specify one particular “count” for each criteria. e.g. you can’t have a list where “two numbers appear twice” because “appear twice” only has one slot. You could make this a list of lists or some other data structure of course.

    Also, it doesn’t eliminate duplicates when it pulls them in. So if we had a criteria of {1, 1, 1} it’d try and pull one number once, one number twice, and one number thrice. But it doesn’t check if any of those are the same number – so it could end up pulling the same number each time and effectively pulling just one number six times instead of 3 separate numbers once, twice, and thrice.

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

Sidebar

Related Questions

How do you generate a random number within a range while excluding certain range(s).
How to generate random number from an array? and not from a range. int
You are given 2^32-2 unique numbers that range from 1 to 2^32-1. It's impossible
I need function which returns: for any number from range => result [0.001,0.01) =>
Generate a random number in range [x..y] where x and y are any arbitrary
Possible Duplicate: Java: generating random number in a range How do I generate a
I have a method to find number in range of iterator like below. I
I need to build a full number range set given a series of numbers.
So I have a function which always returns a number from range <0;99> (i.e.
Given a date range how to calculate the number of weekends partially or wholly

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.