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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:19:42+00:00 2026-06-14T17:19:42+00:00

Alright, so I want to call for (int i = 0; i < b;

  • 0

Alright, so I want to call

for (int i = 0; i < b; b--)
{
    color += ChooseColor() + " ";
}

the important part is that it gets called several times. My ChooseColors() is

private static string ChooseColor()
{
    Random random = new Random();
    var colors = new List<string> { "Blue", "Red", "Green", "Indigo", "Black", "White", "Violet", "Turquoise", "Pink", "Lavender", "Cinder", "Fuschia", "Orange" };
    int index = random.Next(colors.Count);
    string colorName = colors[index];
    colors.RemoveAt(index);
    return colorName;
}

the issue is, I want it to call a new instance of ChooseColor everytime. For instance, it would print Black White instead of Black Black. Right now it prints the exact same thing over and over instead of dumping current and calling again (which is what I thought loops did >.<) any suggestions?

  • 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-14T17:19:43+00:00Added an answer on June 14, 2026 at 5:19 pm

    The array is declared within the method, so it is redeclared and re-filled when you call the method again. You’d have to declare the list of colors statically outside the method.

    Also, the randomizer is initialized again on every method call – initialize the randomizer just once outside the method, too.

    private static Random random = new Random();
    private static List<string> colors = new List<string> { ... };
    
    private static string ChooseColor()
    {
        if (colors.Count > 0)
        {
            int index = random.Next(colors.Count);
            string colorName = colors[index];
            colors.RemoveAt(index);
            return colorName;
        }
    
        return String.Empty;
    }
    

    Please note that this method returns an empty string now when called with no colors left in the list of colors. I think in addition to fixing the randomizer issue, you should really re-think the design (especially why it should be necessary to remove the colors from the list).

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

Sidebar

Related Questions

Alright, I have a wordpress site, that I want to have a clientportal built
Alright, so I have an image that it's resolution is: 1054X1054. I want to
Alright so I want my users to be able to click a link that
Alright so in Java I want to ask the user for a time in
Alright, so I want the user to be able to enter every character from
Alright, here goes. I'm making a very basic app, and I want the user
Alright so i need to open a .txt file that will be created in
Alright, so, I'm doing a little script that downloads X number of wallpapers of
Alright so I want to grab the information on a website thats between [usernames]
Alright here is the thing, I have this site that was once wordpress but

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.