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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:16:34+00:00 2026-05-14T22:16:34+00:00

i am working on a puzzle slider program and trying to randomize images inside

  • 0

i am working on a puzzle slider program and trying to randomize images inside of pictureboxes. I did some research on the internet can’t find any examples i could work on. These are my code:

        Random r = new Random();

        PictureBox[] picBox = new PictureBox[9];
        picBox[0] = new PictureBox();
        picBox[1] = new PictureBox();
        picBox[2] = new PictureBox();
        picBox[3] = new PictureBox();
        picBox[4] = new PictureBox();
        picBox[5] = new PictureBox();
        picBox[6] = new PictureBox();
        picBox[7] = new PictureBox();
        picBox[8] = new PictureBox();

i have bitmap array too:

        Bitmap[] pictures = new Bitmap[9];
        pictures[0] = new Bitmap(@"1.1Bright.jpg");
        pictures[1] = new Bitmap(@"1.2Bright.jpg");
        pictures[2] = new Bitmap(@"1.3Bright.jpg");
        pictures[3] = new Bitmap(@"2.1Bright.jpg");
        pictures[4] = new Bitmap(@"2.2Bright.jpg");
        pictures[5] = new Bitmap(@"2.3Bright.jpg");
        pictures[6] = new Bitmap(@"3.1Bright.jpg");
        pictures[7] = new Bitmap(@"3.2Bright.jpg");
        pictures[8] = new Bitmap(@"3.3Dark.jpg");

i tried a few ways but i don’t know how to set random pictures[] into the picBox[]:

        for(int i=0; i<=8;i++)
        {
            picBox[i].Image= pictures[r.Next(0,9)];
        }

the problem here is that some pictureboxes e.g picBox[1] and picBox[6] are repeated pictures. How do i make them non repeats? Examples are greatly appreciated thanks.

  • 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-14T22:16:34+00:00Added an answer on May 14, 2026 at 10:16 pm

    Create an array of bools equal to the size of the pictures array

    bool[] usedPictures = new bool[pictures.Length];
    

    Set the values of this array to false. Now determine your random number, and test if that element is used or not, something like:

    int iCount = 0;
    Random random = new Random();
    while (iCount < pictures.Length)
    {
        int attempt = random.Next(0, pictures.Length);
    
        //Ensures you will only use an available picture
        if (usedPictures[attempt] == false)
        {            
            picBox[attempt].Image= pictures[iCount];
            doorUsed[attempt] = true;
            iCount++;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.