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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:01:35+00:00 2026-06-18T06:01:35+00:00

Trying to randomize enum values. Problem is the enumerations are in a references file

  • 0

Trying to randomize enum values. Problem is the enumerations are in a references file that I refer to in my code. For example

        public enum AccountTypeEnum
{
        Direct,
        Partner,
        Referral,
        Resold,
}

is in my reference file and in my code I need to refer to AccountTypeEnum and randomize it so when I run my program I can get one of those 4 values.

What I have so far that I believe randomizes the values is this:

   public void AcctType()
        {
            string[] Types = Enum.GetNames(typeof(AccountTypeEnum));            
            Random randType = new Random();
            int randomenum = randType.Next(Types.Length);
            var ret = Enum.Parse(typeof(AccountTypeEnum), Types[randomenum]);
        }

Any suggestions on what I’m doing wrong?

  • 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-18T06:01:36+00:00Added an answer on June 18, 2026 at 6:01 am

    Figured it out. created a new class:

    public class EnumRandomizeer
    {
        public static Random rand = new Random();
        public static T GetRandomValue<T>()
        {
            T[] values = (T[])(Enum.GetValues(typeof(T)));
            return values[rand.Next(0, values.Length)];
        }
    }
    

    And when referencing the enum value I refered to the class like this:

     AccountTypeEnum randomAcct = EnumRandomizeer.GetRandomValue<AccountTypeEnum>();
    

    Worked great!

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

Sidebar

Related Questions

i've been trying to create a vb6 code that will randomize 10 questions but
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
I trying to make a sql script that will randomize the city, state, and
I'm trying to subclass Array in ruby to make it randomize its elements when
I'm trying to create an array of strings that can be randomized and limited
i am working on a puzzle slider program and trying to randomize images inside
I was trying this script from a pdf file.I got stuck where the target
I'm trying to write a unit test for a class that generates distinct strings.
I'm trying to get this Visual Basic program to store values in a multi-dimensional
I'm trying to write a simple encryption algo that is a randomized shift pattern

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.