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

  • Home
  • SEARCH
  • 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 9248135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:53:25+00:00 2026-06-18T09:53:25+00:00

I am trying to figure out how to have my method randomly select an

  • 0

I am trying to figure out how to have my method randomly select an account type from a drop down list. Basically in my web application the user will choose: active, inactive, prospect, or suspended from a drop down list. What I am trying to do is test this functionality and have my method randomly select a value when I run the test.

I am having a hard time referencing the method to the string value in the code if this makes sense. Any help would be great and if you need additional information let me know!

Here is what I have so far:

   public void RandomStatusTypes()
     {
         List<string> statusTypes = new List<string> { "ACTIVE", "INACTIVE", "PROSPECT", "SUSPENDED" };
         Random randStatus = new Random();
         int index = randStatus.Next(0, 6);
         string value = statusTypes[index];
     }

The code will have a line saying StatusTyp = _Status, and hopefully I can assign a random status to the value so everytime I run the program it randomly picks a value.

Thank you!

  • 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-18T09:53:26+00:00Added an answer on June 18, 2026 at 9:53 am

    Perhaps:

    private static List<string> StatusTypes = new List<string>(){ "ACTIVE", "INACTIVE", "PROSPECT", "SUSPENDED" };
    private static Random randStatus = new Random();
    
    public string RandomStatusTypes()
    {
        int index = randStatus.Next(0, StatusTypes.Count);
        return StatusTypes[index];
    }
    

    Don’t create the random instance in the method itself. Otherwise you will create the same statuses when the method is called very fast(f.e. in a loop). You should use a field(as shown above) or pass the random as argument to the method.

    I’ve also moved the list outside of the method since it’s ineffective to create it always when it doesn’t change anyway. Last i’ve used StatusTypes.Count to ensure that you always use a valid range even if you will change the list in future(f.e. add new statuses).

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

Sidebar

Related Questions

I have been trying to figure out a way to tag several methods from
I have been trying to figure out how to open a file from the
Trying to figure out how to create a method that takes in a list
I am trying to figure out something. I have a method which adds some
Im trying to figure out how to have data from multiple models show up
I'm trying to figure out how to have a short, one line conditional statement.
trying to figure out why this is happening - I have an input text
I have been trying to figure out why I am getting this problem and
I have been trying to figure out how to read paragraph content which exists
i`m trying to figure out what if i have 4 textfields field1,field2,field3 and field4,

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.