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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:01:12+00:00 2026-05-26T05:01:12+00:00

For a mini project I am making a quiz program My current (relavant) code

  • 0

For a mini project I am making a quiz program
My current (relavant) code is as follows:

static Random _r = new Random();        
static int Quiz()
{
    string[,] QAndA = {
        {"What is the capital of France", "Paris"},
        {"What is the capital of Spain", "Madrid"},
                ...
        {"What is the captial of Russia", "Moscow"},
        {"What is the capital of Ukraine", "Kiev"},
    };

    for (int i = 0; i < NUM_QUESTIONS; i++)
    {
        int num = _r.Next(QAndA.GetLength(0) / 2);
        Question(QAndA[num, 0], QAndA[num, 1]);
    }
}

Now, the obvious problem with this is that the random numbers can be repeated, meaning that questions can be repeated.

Now, my teacher (yes, this is a school thing) told me to look for shuffling algorithms, but I have failed to find any that work for multidimensional arrays like i have used.

I am a fairly new c# programmer, but I have experience with c++
and the program is a commandline program (at the moment 🙂 ), if that matters/helps

So, the question is, what’s the best way of reordering/shuffling the multidimensional array to be in a random order?

  • 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-26T05:01:13+00:00Added an answer on May 26, 2026 at 5:01 am

    You are looking at the wrong problem. Instead of a multidimensional array (something quite rarely used because scarcely supported) use a jagged array.

    string[][] questions = new[] { 
        new [] {"What is the capital of France", "Paris"}, 
        new [] {"What is the capital of Spain", "Madrid"},
        new [] {"What is the captial of Russia", "Moscow"},
        new [] {"What is the capital of Ukraine", "Kiev"},
    };
    
    // use: questions[0][0] (question), questions[0][1] (answer), questions[1][0] (question)...
    

    or (better) create a class with two members, Question and Answer.

    class QuestionAndAnswer
    {
        public string Question { get; protected set; }
        public string Answer { get; protected set; }
    
        public QuestionAndAnswer(string question, string answer)
        {
            this.Question = question;
            this.Answer = answer;
        }
    }
    
    QuestionAndAnswer[] questions = new QuestionAndAnswer[] { 
        new QuestionAndAnswer("What is the capital of France", "Paris"),
        new QuestionAndAnswer("What is the capital of Spain", "Madrid"),
        // ...
    };
    
    // use: questions[0].Question, questions[0].Answer...
    

    You could then use the Knuth algorithm 🙂

    Quoting from there:

    To shuffle an array a of n elements (indexes 0..n-1):
      for i from n − 1 downto 1 do
           j ← random integer with 0 ≤ j ≤ i
           exchange a[j] and a[i]
    

    In C# the algorithm will be something like

    Random rnd = new Random();
    
    for (int i = questions.Length - 1; i >= 1; i--)
    {
        // Random.Next generates numbers between min and max - 1 value, so we have to balance this
        int j = rnd.Next(0, i + 1);
    
        if (i != j)
        {
            var temp = questions[i];
            questions[i] = questions[j];
            questions[j] = temp;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a mini ORM for a Java program I'm writing... there is a
I am new to DDD. In my mini-project, I have a structure that looks
I'm new to Python and I'm starting a mini Project, but I have some
I need to come up with a regular expression for a mini-project. The string
Good Evening, I am pretty new to Unix so maybe this mini project is
I got into a mini-argument with my boss recently regarding project failure. After three
My most used mini pattern is: VideoLookup = new ArrayList { new ArrayList {
I have written a mini web-server which needs to serve up a few static
As part of the college mini-project, I am developing a micro-blogging platform for Android.
I'm using C# for a mini project of mine, I am trying to monitor

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.