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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:46:34+00:00 2026-05-31T10:46:34+00:00

I have 1000 unique objects in a java.util.List , each referring to an image,

  • 0

I have 1000 unique objects in a java.util.List, each referring to an image, each image in the 1000-list is unique and now I’d like to shuffle them, so that I can use the first 20 objects and present them to the website-user.
The user can then click a button saying “Shuffle”, and I retrieve the 1000 images again from scratch and calling again shuffle().
However, it seems that out of 1000 image objects, I very often see the same image again and again between the 20-image-selections.

Something seems to be wrong, any better suggestion, advices?

My code is very simple:

List<String> imagePaths = get1000Images();
Collections.shuffle(imagePaths);

int i = 0;
for (String path: imagePaths) {
  ... do something with the path ...
  i++;
  if (i >= 20) break;
}

I know that Collections.shuffle() is well distributed:
see for instance http://blog.ryanrampersad.com/2012/03/03/more-on-shuffling-an-array-correctly/

However, I just have the feeling that the probability of seeing the same image over and over again in a set of 20 images out of 1000 should be much less…

Inputs highly appreciated.

  • 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-31T10:46:36+00:00Added an answer on May 31, 2026 at 10:46 am

    If you’re showing 20 images out of 1000 the probability of seeing any one of that 20 repeated in the next iteration is approximately 0.34 so you shouldn’t be surprised to see images repeating.

    The chances of seeing a specific image is still one in a thousand, but if you’re looking for twenty images the chances are much higher.

    We can calculate the probability of none of the previous 20 images repeating as:

     980   979         961
    ———— × ——— × ... × ——— ≈ 0.66
    1000   999         981
    

    And so the probability of seeing a repeat is one minus this, or approximately 0.34.

    And the probability of seeing an image repeated in either of the next two iterations is:

    1 - (0.66 × 0.66) ≈ 0.56
    

    In other words, it’s more likely than not that you’ll see a repeated image over the two following cycles. (And this isn’t including images repeated from the second cycle in the third which will only make it more likely.)

    For what it’s worth, here’s some Java code to do the above calculation:

    float result = 1.0f;
    int totalImages = 1000;
    int displayedImages = 20;
    
    for (int i = 0; i < displayedImages; i++) {
      result = result * (totalImages - displayedImages - i) / (totalImages - i);
    }
    
    System.out.println(result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have 1000 encrypted workbooks which I would like to decrypt by providing
I have around 1000 pdf filesand I need to convert them to 300 dpi
We have over 1000 unit tests. A while ago 18 of them started to
Say there is a website with 100,000 users each has up to 1000 unique
I have a large dataset with documents that sometimes cross-reference each other, sometimes do
I have a table containing numbers, range between 1-1000 they are unique, but I
I have a slightly unique requirement with the Java-JDBC API along with Oracle Database.
I have say list of 1000 beans which I need to share among different
I have a list of users on my php application (using codeigniter). Each user
In a database we have about 1000 registered users. I'd like to know how

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.