5
\$\begingroup\$

The code below has many Lists<> but I'm not sure how to modify it. The only thing here that is an algorithm is the Fisher Yates shuffle algorithm. I am trying to put in good use an algorithm or just code better said to do this. It seems a bunch of code just used in repetition.

My question is, is there a way to make this code better? My task is to randomize names either male or female. The ListBox should stay like this. I don't want them to do much but just be there. Like the Country or birth date. How can improve this code to make it look cleaner and better? I am not concerned about the shuffler algorithm but more of the code that I have wrote down on here.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PerfectName
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
 public partial class MainWindow : Window
 {
    ListBoxItem item1;
    List<string> MaleNamesThatStartWithA;
    List<string> MaleNamesThatStartWithB;
    List<string> MaleNamesThatStartWithC;
    List<string> MaleNamesThatStartWithD;
    List<string> MaleNamesThatStartWithE;
    List<string> MaleNamesThatStartWithF;
    List<string> MaleNamesThatStartWithG;
    List<string> MaleNamesThatStartWithH;
    List<string> MaleNamesThatStartWithI;
    List<string> MaleNamesThatStartWithJ;
    List<string> MaleNamesThatStartWithK;
    List<string> MaleNamesThatStartWithL;
    List<string> MaleNamesThatStartWithM;
    List<string> MaleNamesThatStartWithN;
    List<string> MaleNamesThatStartWithO;
    List<string> MaleNamesThatStartWithP;
    List<string> MaleNamesThatStartWithQ;
    List<string> MaleNamesThatStartWithR;
    List<string> MaleNamesThatStartWithS;
    List<string> MaleNamesThatStartWithT;
    List<string> MaleNamesThatStartWithU;
    List<string> MaleNamesThatStartWithV;
    List<string> MaleNamesThatStartWithW;
    List<string> MaleNamesThatStartWithX;
    List<string> MaleNamesThatStartWithY;
    List<string> MaleNamesThatStartWithZ;

    List<string> FemaleNamesThatStartWithA;
    List<string> FemaleNamesThatStartWithB;
    List<string> FemaleNamesThatStartWithC;
    List<string> FemaleNamesThatStartWithD;
    List<string> FemaleNamesThatStartWithE;
    List<string> FemaleNamesThatStartWithF;
    List<string> FemaleNamesThatStartWithG;
    List<string> FemaleNamesThatStartWithH;
    List<string> FemaleNamesThatStartWithI;
    List<string> FemaleNamesThatStartWithJ;
    List<string> FemaleNamesThatStartWithK;
    List<string> FemaleNamesThatStartWithL;
    List<string> FemaleNamesThatStartWithM;
    List<string> FemaleNamesThatStartWithN;
    List<string> FemaleNamesThatStartWithO;
    List<string> FemaleNamesThatStartWithP;
    List<string> FemaleNamesThatStartWithQ;
    List<string> FemaleNamesThatStartWithR;
    List<string> FemaleNamesThatStartWithS;
    List<string> FemaleNamesThatStartWithT;
    List<string> FemaleNamesThatStartWithU;
    List<string> FemaleNamesThatStartWithV;
    List<string> FemaleNamesThatStartWithW;
    List<string> FemaleNamesThatStartWithX;
    List<string> FemaleNamesThatStartWithY;
    List<string> FemaleNamesThatStartWithZ;
    public MainWindow()
    {
        InitializeComponent();
        MaleNamesThatStartWithA = new List<string>();
        MaleNamesThatStartWithA.Add("Arnie");
        MaleNamesThatStartWithA.Add("Albert");

        MaleNamesThatStartWithB = new List<string>();
        MaleNamesThatStartWithB.Add("Bart");
        MaleNamesThatStartWithB.Add("Bernie");

        MaleNamesThatStartWithC = new List<string>();
        MaleNamesThatStartWithC.Add("Catherine");
        MaleNamesThatStartWithC.Add("Caroline");

        MaleNamesThatStartWithD = new List<string>();
        MaleNamesThatStartWithD.Add("Dilbert");
        MaleNamesThatStartWithD.Add("Danial");

        MaleNamesThatStartWithE = new List<string>();
        MaleNamesThatStartWithE.Add("Evan");
        MaleNamesThatStartWithE.Add("Ethan");

        MaleNamesThatStartWithF = new List<string>();
        MaleNamesThatStartWithF.Add("Frank");
        MaleNamesThatStartWithF.Add("Frankie");

        MaleNamesThatStartWithG = new List<string>();
        MaleNamesThatStartWithG.Add("Grover");
        MaleNamesThatStartWithG.Add("Gabriel");

        MaleNamesThatStartWithH = new List<string>();
        MaleNamesThatStartWithH.Add("Harold");
        MaleNamesThatStartWithH.Add("Harry");

        MaleNamesThatStartWithI = new List<string>();
        MaleNamesThatStartWithI.Add("Ivan");
        MaleNamesThatStartWithI.Add("Iuri");

        MaleNamesThatStartWithJ = new List<string>();
        MaleNamesThatStartWithJ.Add("James");
        MaleNamesThatStartWithJ.Add("Jim");

        MaleNamesThatStartWithK = new List<string>();
        MaleNamesThatStartWithK.Add("Kyle");
        MaleNamesThatStartWithK.Add("Kory");

        MaleNamesThatStartWithL = new List<string>();
        MaleNamesThatStartWithL.Add("Leon");
        MaleNamesThatStartWithL.Add("Larry");

        MaleNamesThatStartWithM = new List<string>();
        MaleNamesThatStartWithM.Add("Martin");
        MaleNamesThatStartWithM.Add("Mario");

        MaleNamesThatStartWithN = new List<string>();
        MaleNamesThatStartWithN.Add("Neto");
        MaleNamesThatStartWithN.Add("Nathan");

        MaleNamesThatStartWithO = new List<string>();
        MaleNamesThatStartWithO.Add("Omar");
        MaleNamesThatStartWithO.Add("Omarion");

        MaleNamesThatStartWithP = new List<string>();
        MaleNamesThatStartWithP.Add("Peter");
        MaleNamesThatStartWithP.Add("Pedro");

        MaleNamesThatStartWithQ = new List<string>();
        MaleNamesThatStartWithQ.Add("Quil");
        MaleNamesThatStartWithQ.Add("Quavo");

        MaleNamesThatStartWithR = new List<string>();
        MaleNamesThatStartWithR.Add("Rico");
        MaleNamesThatStartWithR.Add("Robert");

        MaleNamesThatStartWithS = new List<string>();
        MaleNamesThatStartWithS.Add("Stewart");
        MaleNamesThatStartWithS.Add("Steven");

        MaleNamesThatStartWithT = new List<string>();
        MaleNamesThatStartWithT.Add("Tom");
        MaleNamesThatStartWithT.Add("Todd");

        MaleNamesThatStartWithU = new List<string>();
        MaleNamesThatStartWithU.Add("Ustavo");
        MaleNamesThatStartWithU.Add("Ulisius");

        MaleNamesThatStartWithV = new List<string>();
        MaleNamesThatStartWithV.Add("Victor");
        MaleNamesThatStartWithV.Add("Vinny");

        MaleNamesThatStartWithW = new List<string>();
        MaleNamesThatStartWithW.Add("Will");
        MaleNamesThatStartWithW.Add("William");

        MaleNamesThatStartWithX = new List<string>();
        MaleNamesThatStartWithX.Add("Xaviar");
        MaleNamesThatStartWithX.Add("Xumeo");

        MaleNamesThatStartWithY = new List<string>();
        MaleNamesThatStartWithY.Add("Yolondo");
        MaleNamesThatStartWithY.Add("Yuvio");

        MaleNamesThatStartWithZ = new List<string>();
        MaleNamesThatStartWithZ.Add("Zether");
        MaleNamesThatStartWithZ.Add("Zeypher");

        FemaleNamesThatStartWithA = new List<string>();
        FemaleNamesThatStartWithA.Add("Alice");
        FemaleNamesThatStartWithA.Add("Amber");

        FemaleNamesThatStartWithB = new List<string>();
        FemaleNamesThatStartWithB.Add("Bernadette");
        FemaleNamesThatStartWithB.Add("Betsy");

        FemaleNamesThatStartWithC = new List<string>();
        FemaleNamesThatStartWithC.Add("Catherine");
        FemaleNamesThatStartWithC.Add("Cathy");

        FemaleNamesThatStartWithD = new List<string>();
        FemaleNamesThatStartWithD.Add("Dania");
        FemaleNamesThatStartWithD.Add("Day");

        FemaleNamesThatStartWithE = new List<string>();
        FemaleNamesThatStartWithE.Add("Esther");
        FemaleNamesThatStartWithE.Add("Etssy");

        FemaleNamesThatStartWithF = new List<string>();
        FemaleNamesThatStartWithF.Add("Faria");
        FemaleNamesThatStartWithF.Add("Floria");

        FemaleNamesThatStartWithG = new List<string>();
        FemaleNamesThatStartWithG.Add("Grace");
        FemaleNamesThatStartWithG.Add("Gracie");

        FemaleNamesThatStartWithH = new List<string>();
        FemaleNamesThatStartWithH.Add("Hello");
        FemaleNamesThatStartWithH.Add("Happy");

        FemaleNamesThatStartWithI = new List<string>();
        FemaleNamesThatStartWithI.Add("Isuvia");
        FemaleNamesThatStartWithI.Add("Isabella");

        FemaleNamesThatStartWithJ = new List<string>();
        FemaleNamesThatStartWithJ.Add("Joy");
        FemaleNamesThatStartWithJ.Add("Joyce");

        FemaleNamesThatStartWithK = new List<string>();
        FemaleNamesThatStartWithK.Add("Kate");
        FemaleNamesThatStartWithK.Add("Kathy");

        FemaleNamesThatStartWithL = new List<string>();
        FemaleNamesThatStartWithL.Add("Lucy");
        FemaleNamesThatStartWithL.Add("Lin");

        FemaleNamesThatStartWithM = new List<string>();
        FemaleNamesThatStartWithM.Add("Maria");
        FemaleNamesThatStartWithM.Add("Margot");

        FemaleNamesThatStartWithN = new List<string>();
        FemaleNamesThatStartWithN.Add("Nuvia");
        FemaleNamesThatStartWithN.Add("Nancy");

        FemaleNamesThatStartWithO = new List<string>();
        FemaleNamesThatStartWithO.Add("Osakia");
        FemaleNamesThatStartWithO.Add("Osaku");

        FemaleNamesThatStartWithP = new List<string>();
        FemaleNamesThatStartWithP.Add("Patty");
        FemaleNamesThatStartWithP.Add("Patricia");

        FemaleNamesThatStartWithQ = new List<string>();
        FemaleNamesThatStartWithQ.Add("Quava");
        FemaleNamesThatStartWithQ.Add("Quisha");

        FemaleNamesThatStartWithR = new List<string>();
        FemaleNamesThatStartWithR.Add("Rita");
        FemaleNamesThatStartWithR.Add("Riri");

        FemaleNamesThatStartWithS = new List<string>();
        FemaleNamesThatStartWithS.Add("Suzy");
        FemaleNamesThatStartWithS.Add("Susan");

        FemaleNamesThatStartWithT = new List<string>();
        FemaleNamesThatStartWithT.Add("Tanya");
        FemaleNamesThatStartWithT.Add("TIffany");

        FemaleNamesThatStartWithU = new List<string>();
        FemaleNamesThatStartWithU.Add("Uvia");
        FemaleNamesThatStartWithU.Add("Urania");

        FemaleNamesThatStartWithV = new List<string>();
        FemaleNamesThatStartWithV.Add("Vanessa");
        FemaleNamesThatStartWithV.Add("Vania");

        FemaleNamesThatStartWithW = new List<string>();
        FemaleNamesThatStartWithW.Add("Wendy");
        FemaleNamesThatStartWithW.Add("War");

        FemaleNamesThatStartWithX = new List<string>();
        FemaleNamesThatStartWithX.Add("Xuvia");
        FemaleNamesThatStartWithX.Add("Xuia");

        FemaleNamesThatStartWithY = new List<string>();
        FemaleNamesThatStartWithY.Add("Yolonda");
        FemaleNamesThatStartWithY.Add("Yosi");

        FemaleNamesThatStartWithZ = new List<string>();
        FemaleNamesThatStartWithZ.Add("Zania");
        FemaleNamesThatStartWithZ.Add("Zuvia");

        item1 = new ListBoxItem();
        item1.Content = "German";
        ListBoxItem item2 = new ListBoxItem();
        item2.Content = "American";

        listBox1.Items.Add(item1);
        listBox1.Items.Add(item2);

        ListBoxItem sign1 = new ListBoxItem();
        sign1.Content = "Cancer";
        ListBoxItem sign2 = new ListBoxItem();
        sign2.Content = "Gemini";

        listBox2.Items.Add(sign1);
        listBox2.Items.Add(sign2);

        ListBoxItem bday1 = new ListBoxItem();
        bday1.Content = "1900";
        ListBoxItem bday2 = new ListBoxItem();
        bday2.Content = "1901";

        listBox3.Items.Add(bday1);
        listBox3.Items.Add(bday2);




    }

    private string ShuffleNames(List<string> name)
    {
        Random random = new Random();
        string tmp = "";
        int length = name.Count;
        for (int i = 0; i < length; i++)
        {
            int r = (int)(random.NextDouble() * (length - i));
            tmp = name[r];
            name[r] = name[i];
            name[i] = tmp;
        }

        return tmp;
    }
    private void Submit(object sender, RoutedEventArgs e)
    {
        try{
            if (radioButton1.IsChecked != null && radioButton2.IsChecked != null && listBox3.SelectedItem.ToString() != null && listBox2.SelectedItem.ToString() != null && listBox1.SelectedItem.ToString() != null)
            {
                if (radioButton1.IsChecked == true && textBox1.Text == "A" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithA);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "A" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithA);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "B" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithB);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "B" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithB);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "C" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithC);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "C" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithC);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "D" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithD);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "D" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithD);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "E" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithE);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "E" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithE);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "F" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithF);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "F" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithF);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "G" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithG);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "G" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithG);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "H" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithH);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "H" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithH);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "J" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithJ);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "J" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithJ);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "K" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithK);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "K" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithK);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "L" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithL);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "L" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithL);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "M" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithM);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "M" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithM);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "N" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithN);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "N" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithN);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "O" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithO);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "O" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithO);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "P" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithP);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "P" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithP);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "Q" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithQ);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "Q" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithQ);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "R" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithR);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "R" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithR);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "S" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithS);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "S" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithS);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "T" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithT);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "T" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithT);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "U" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithU);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "U" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithU);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "V" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithV);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "V" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithV);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "W" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithW);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "W" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithW);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "X" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithX);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "X" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithX);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "Y" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithY);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "Y" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithY);
                }
                else if (radioButton1.IsChecked == true && textBox1.Text == "Z" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(MaleNamesThatStartWithZ);
                }
                else if (radioButton2.IsChecked == true && textBox1.Text == "Z" && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(FemaleNamesThatStartWithZ);
                }
                else
                {
                    label3.Content = "Fill in form";
                }
            }
        } catch(NullReferenceException nre){
            MessageBox.Show("Please fill in form");
            Console.WriteLine(nre.GetBaseException());
        }
    }
}
}
\$\endgroup\$
4
  • 5
    \$\begingroup\$ Wow, that's a lot of needless repetition. \$\endgroup\$
    – Mast
    Sep 16, 2016 at 20:33
  • \$\begingroup\$ Is there a way of making this code smaller? WIthout the repetition @Mast \$\endgroup\$
    – noob1992
    Sep 16, 2016 at 20:35
  • \$\begingroup\$ If you're new to C#, consider adding the beginner tag to your question. \$\endgroup\$
    – Mast
    Sep 16, 2016 at 21:21
  • \$\begingroup\$ Why shuffle if you just need one random? \$\endgroup\$
    – paparazzo
    Sep 17, 2016 at 16:46

5 Answers 5

7
\$\begingroup\$

The logic part of your code should definitely be re-written, but since it's one big mess I'm not going to touch that. See whether you really need that many options. You probably don't. I might expand on this anyway later on, since code like this hurts.

However, I can tell you this smells:

List<string> MaleNamesThatStartWithA;
List<string> MaleNamesThatStartWithB;
List<string> MaleNamesThatStartWithC;
List<string> MaleNamesThatStartWithD;
List<string> MaleNamesThatStartWithE;
List<string> MaleNamesThatStartWithF;
List<string> MaleNamesThatStartWithG;
List<string> MaleNamesThatStartWithH;
List<string> MaleNamesThatStartWithI;
List<string> MaleNamesThatStartWithJ;
List<string> MaleNamesThatStartWithK;
List<string> MaleNamesThatStartWithL;
List<string> MaleNamesThatStartWithM;
List<string> MaleNamesThatStartWithN;
List<string> MaleNamesThatStartWithO;
List<string> MaleNamesThatStartWithP;
List<string> MaleNamesThatStartWithQ;
List<string> MaleNamesThatStartWithR;
List<string> MaleNamesThatStartWithS;
List<string> MaleNamesThatStartWithT;
List<string> MaleNamesThatStartWithU;
List<string> MaleNamesThatStartWithV;
List<string> MaleNamesThatStartWithW;
List<string> MaleNamesThatStartWithX;
List<string> MaleNamesThatStartWithY;
List<string> MaleNamesThatStartWithZ;

List<string> FemaleNamesThatStartWithA;
List<string> FemaleNamesThatStartWithB;
List<string> FemaleNamesThatStartWithC;
List<string> FemaleNamesThatStartWithD;
List<string> FemaleNamesThatStartWithE;
List<string> FemaleNamesThatStartWithF;
List<string> FemaleNamesThatStartWithG;
List<string> FemaleNamesThatStartWithH;
List<string> FemaleNamesThatStartWithI;
List<string> FemaleNamesThatStartWithJ;
List<string> FemaleNamesThatStartWithK;
List<string> FemaleNamesThatStartWithL;
List<string> FemaleNamesThatStartWithM;
List<string> FemaleNamesThatStartWithN;
List<string> FemaleNamesThatStartWithO;
List<string> FemaleNamesThatStartWithP;
List<string> FemaleNamesThatStartWithQ;
List<string> FemaleNamesThatStartWithR;
List<string> FemaleNamesThatStartWithS;
List<string> FemaleNamesThatStartWithT;
List<string> FemaleNamesThatStartWithU;
List<string> FemaleNamesThatStartWithV;
List<string> FemaleNamesThatStartWithW;
List<string> FemaleNamesThatStartWithX;
List<string> FemaleNamesThatStartWithY;
List<string> FemaleNamesThatStartWithZ;

For one, did you notice the list of FemaleNames is an exact copy of the list of MaleNames? Did you also notice how there's exactly 26 letters in the alphabet and this is not likely to change? Did you also notice the location of the letter in the alphabet is not likely to change?

So why don't we simply write those lists into more lists?

List<List<string>> MaleNames;
List<List<string>> FemaleNames;

There. Done. I just threw out 50 lines of code.

Instead of adding something to MaleNamesThatStartWithA, you now add something to MaleNames[12].
Instead of adding something to FemaleNamesThatStartWithB, you now add something to FemaleNames[1].

The following makes me think you really wanted to create a Person object instead:

item1 = new ListBoxItem();
item1.Content = "German";
ListBoxItem item2 = new ListBoxItem();
item2.Content = "American";

listBox1.Items.Add(item1);
listBox1.Items.Add(item2);

ListBoxItem sign1 = new ListBoxItem();
sign1.Content = "Cancer";
ListBoxItem sign2 = new ListBoxItem();
sign2.Content = "Gemini";

listBox2.Items.Add(sign1);
listBox2.Items.Add(sign2);

ListBoxItem bday1 = new ListBoxItem();
bday1.Content = "1900";
ListBoxItem bday2 = new ListBoxItem();
bday2.Content = "1901";

listBox3.Items.Add(bday1);
listBox3.Items.Add(bday2);

You really don't want to name a variable item1. It's ambiguous.

So how about a Class containing all the relevant information of a Person?

class Person
{
    public Person(string fn, string ln, DateTime dob, string nat, string sig)  //Parameterized constructor
    {
       FirstName   = fn;
       LastName    = ln;
       DateOfBirth = dob;
       Nationality = nat;
       Sign        = sig;
    }
    public string   FirstName   { get; set; }
    public string   LastName    { get; set; }
    public DateTime DateOfBirth { get; set; }
    public string   Nationality { get; set; }
    public string   Sign        { get; set; }
}

Now, all of a sudden, you can do this:

MaleNames[3].Add(new Person { "Doug", "Howitzer", new DateTime(1974, 7, 10, 7, 10, 24), "German", "Zodiac" });

All at once!

Keep in mind we suddenly changed the type of what we're adding to the List, so now we instantiate like this:

List<List<Person>> MaleNames;
List<List<Person>> FemaleNames;
\$\endgroup\$
9
  • \$\begingroup\$ Okay I appreciate your answer \$\endgroup\$
    – noob1992
    Sep 16, 2016 at 20:55
  • \$\begingroup\$ @noob1992 I expanded a bit on it. Do you understand it or is there anything I should add for clarification? \$\endgroup\$
    – Mast
    Sep 16, 2016 at 21:06
  • \$\begingroup\$ yes I was looking for something like this instead what I have written out . Maybe I should have started with OOP instead I didn't think about that. Yeah creating a Person Object instead would be much easier and better to handle for me. Thank You ! and @Mat'sMug what do you mean this guy did me a solid ! \$\endgroup\$
    – noob1992
    Sep 16, 2016 at 21:10
  • \$\begingroup\$ But i can see where this would be crucial in the programming world @Mat'sMug \$\endgroup\$
    – noob1992
    Sep 16, 2016 at 21:11
  • 1
    \$\begingroup\$ @ColinBasnett Yes, something along those lines has been suggested by fernando.reyes. \$\endgroup\$
    – Mast
    Sep 17, 2016 at 10:45
5
\$\begingroup\$

Instead of two lists like @Mast proposed, you could use a Dictionary and a List like:

public Dictionary<string, List<string>> maleNames = new Dictionary<string, List<string>>(){
            {"A", new List<string>(){"Arnie", "Albert"}},
            {"B", new List<string>(){"Bart", "Bernie"}},
        };

That way you can have an easy initialization.

And you can add to your list like:

maleNames["A"].Add("Arnold");
maleNames["Z"].Add("Zonic");`

And the mess in the submit button will be like:

try{
            if (radioButton1.IsChecked != null && radioButton2.IsChecked != null && listBox3.SelectedItem.ToString() != null && listBox2.SelectedItem.ToString() != null && listBox1.SelectedItem.ToString() != null)
            {
                if (radioButton1.IsChecked == true && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(maleNames[textBox1.Text]);
                }
                else if (radioButton2.IsChecked == true && listBox3.SelectedItem.ToString() == listBox3.SelectedValue.ToString() && listBox2.SelectedItem.ToString() == listBox2.SelectedValue.ToString() && listBox1.SelectedItem.ToString() == listBox1.SelectedValue.ToString())
                {
                    label3.Content = ShuffleNames(femaleNames[textBox1.Text]);
                }
           }
}
\$\endgroup\$
2
  • \$\begingroup\$ Got it ! If it makes anyone feel better I haven't written code for a month or so . Sorry for posted such a block of a mess . haha \$\endgroup\$
    – noob1992
    Sep 16, 2016 at 21:16
  • 1
    \$\begingroup\$ A Dictionary is definitely better readable, good call. \$\endgroup\$
    – Mast
    Sep 16, 2016 at 21:18
1
\$\begingroup\$

People have suggested using nested Lists or a Dictionary to keep lists of all the names that begin with different letters, but I'm going to suggest perhaps getting rid of having the names separated by what letter they start with. You could easily obtain that with a List of all the names.

public List<String> getNamesThatStartWith(List<String names, char letter) {
    List<String> filteredNames = new ArrayList<>();  
    for (String name : names) {
        if (name.startsWith(letter)) {
            filteredNames.add(name);
        }
    }
    return filteredNames;
}

If you use Person objects as @Mast suggested you can even get rid of the different Lists for male and female. For example by doing something like this:

public List<Person> getAllMales(List<Person> list) {
    List<Person> result = new ArrayList<>();
    for (Person person : list) {
        if (person.gender == male)
            result.add(person);
    }
    return result;
}

You could then easily get the names you want by slightly altering the getNamesStartingWith to use Person object allowing for an easy call such as:

List<Person> people = new ArrayList<>();
//populate it with all kinds of people both male, female with names starting with all kinds of letters

List<Person> result = getNamesThatStartWith(getAllMales(people), "A");
//ProTip: Use .NET extension methods to make this look really good.
//This is what it would look like:
//    List<Person> result = people.getMales().getNamesThatStartWith("A");

Using this concept you could clean up your submit() method signifigantly!

Something like this:

//This is a rough draft since I'm not sure what all of your controls do. They really need to be better named
//I'm using radiobutton1 to mean use male list and radiobutton2 to mean females. I assume textBox1 is the letter to filter by.
public void submit() {
    List<Person> people = new ArrayList<>();

    //leave out the == true, booleans don't need that
    if (radioButton1.isChecked) {
        label3.content = ShuffleNames(people.getMales().getNamesStartingWith((char)textBox1.Text));
    } else {
        label3.content = ShuffleNames(people.getFeales().getNamesStartingWith((char)textBox1.Text));        
    }
}

Congrats you just brought that 100+ line if-else mess method down to about 10 lines!

Couple of other points:

  • if statements don't need the == true or == false. you can just do if(booleanValue) or if(!booleanValue)
  • Your controls need to be better named so that people know what they do and represent.
\$\endgroup\$
4
  • \$\begingroup\$ That is great for readability but all the filtering is not good for performance. Although I don't think in this application performance is gonna be an issue, just to point it out. \$\endgroup\$ Sep 16, 2016 at 22:00
  • 1
    \$\begingroup\$ this is not even C#, what is this: ArrayList<> or for (Person person : list)? :-| \$\endgroup\$
    – t3chb0t
    Sep 17, 2016 at 3:55
  • \$\begingroup\$ Why don't you follow the C# naming convention? It's not JavaScript to use camelCase ;-] \$\endgroup\$
    – t3chb0t
    Sep 17, 2016 at 5:16
  • \$\begingroup\$ @t3chb0t I generally program in Java and therefore am used to dealing with those conventions. for (Person person : list) is the Java foreach loop. I didn't realize C# had different syntax but they're pretty close. ArrayList in Java is a generic construct. Is it not like that in C#? \$\endgroup\$
    – yitzih
    Sep 18, 2016 at 5:03
0
\$\begingroup\$

You are are shuffling but really just returning a random This is with and indexer
Just all them all to PeoplesCollection

public partial class MainWindow : Window
{
    private PersonCollection personCollection = new PersonCollection();
    public MainWindow()
    {
        InitializeComponent();
        personCollection.Persons.Add(new Person("John", enumSex.male));
        // ...
    }

    public PersonCollection Peeps { get { return personCollection; } }
    private void Submit(object sender, RoutedEventArgs e)
    {
        label3.Content = personCollection(textBox1.Text, radioButton1.IsChecked ? enumSex.female : enumSex.female; );
    }
}
public enum enumSex { male, female };   
public class PersonCollection
{
    Random rand = new Random();
    // Declare an array to store the data elements.
    private List<Person> persons = new List<Person>();
    public List<Person> Persons { get { return persons; } }
    // Define the indexer, which will allow client code
    // to use [] notation on the class instance itself.
    // (See line 2 of code in Main below.)        
    public Person this [char c, enumSex sex]
    {
        get
        {
            List<Person> peeps = persons.Where(x => x.Sex == sex).ToList();
            if (peeps.Count == 0)
                return null;
            return peeps[rand.Next(peeps.Count)];
            // This indexer is very simple, and just returns or sets
            // the corresponding element from the internal array.
        }
    }
}
public class Person
{
    public string Name;
    public char FirstLetter
    {
        get
        {
            if (string.IsNullOrEmpty(Name))
                return ' ';
            else
                return Name.ToCharArray()[0];
        }
    }
    public enumSex Sex;
    public Person(string name, enumSex sex)
    {
        Name = name;
        Sex = sex;
    }
}
\$\endgroup\$
-1
\$\begingroup\$

Since you asked explicitly about the shuffling, I would clean up the code like this:

private void ShuffleNames(List<string> name)
{
    Random random = new Random();
    // string tmp = ""; don't declare variables at a scope greater than you need, and don't assign values you don't need
    // int length = name.Count; you don't need a separate variable for this
    for (int i = 0; i < name.Count; i++)
    {
        int r = random.Next(name.Count);
        String tmp = name[r];
        name[r] = name[i];
        name[i] = tmp;
    }

    // return tmp; why was this the return value?
}

That said, this doesn't seem to implement Fisher-Yates. The pseudo-code in Wikipedia is pretty clear. In particular, note that the upper limit passed to random.Next in your implementation is always name.Count. The whole point of Fisher-Yates is that the random numbers used to drive the swap come from a ranges of 2, 3, 4, ... n. This makes the mapping onto the n! shuffles injective.

\$\endgroup\$
4
  • \$\begingroup\$ Yes that is more better and less confusing . \$\endgroup\$
    – noob1992
    Sep 16, 2016 at 21:23
  • \$\begingroup\$ @noob1992 Also, you should take care to implement the Fisher-Yates shuffle properly. blog.codinghorror.com/the-danger-of-naivete \$\endgroup\$
    – jamesdlin
    Sep 16, 2016 at 22:07
  • \$\begingroup\$ The originally posted code seems to implement the shuffling correct, since it uses Count - i. \$\endgroup\$ Sep 17, 2016 at 8:18
  • \$\begingroup\$ @RolandIllig The originally posted code does not implement it correctly because it neglects to exclude already-picked items from the selection space. That is, it does not increment r by i (and therefore won't be able to pick items from the tail end of the array). \$\endgroup\$
    – jamesdlin
    Sep 17, 2016 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.