Randomly assign array value with another array's value












-3















How do I assign one set of array values with another array's values? Both have 26 values.



I'm emulating a Deal or No Deal game where the user chooses a case from a specified list. Now, on each run of the console app I want there to be a random assignment for each cash prize to each case (for fairness sakes). My code is of the following:



    int cashPrizeArray = new int { 0, 1, 2, 5, 10, 20, 50, 100, 150, 200, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 10000, 15000, 20000, 25000, 50000, 75000, 100000, 200000 };
string caseArray = new string { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26" };

Console.WriteLine("Deal or Not!");
Console.Write("Choose a case: 1-26: ");
string userCase = Console.ReadLine();



if (!caseArray.Contains(userCase))
{
Console.WriteLine("nUnexpected input text.nThis application will now be terminated.nPress ENTER to continue...");
Console.ReadLine();
Environment.Exit(0);
}

else
{
Console.WriteLine("You chose case " + userCase);
Console.ReadLine();
}


I will need to reference these cases one by one when a user chooses them, and then remove them from being called in the array once initially opened.










share|improve this question




















  • 1





    And you have a question?

    – Enigmativity
    Nov 23 '18 at 1:28






  • 2





    Search for shuffle c# dozens and dozens of answers here ready and waiting for you to find them

    – None of the Above
    Nov 23 '18 at 1:30













  • @Enigmativity How do I assign one set of array values with another array's values? Both have 26 values.

    – kzone95
    Nov 23 '18 at 1:32











  • @kzone95: It's not clear to me what you even mean by "assign one set of array values with another array's values". So far your program has two arrays and accepts one input value from the user. Is something not working in that code? If your code is working and you're looking to move on to your next step, what is that step? Logically break down the problem into small and specific pieces. Which piece are you trying next? What have you tried?

    – David
    Nov 23 '18 at 1:35











  • Define a field in your class private static Random _rnd = new Random(); then on the line after you have defined cashPrizeArray put this: cashPrizeArray = cashPrizeArray.OrderBy(x => _rnd.Next()).ToArray();.

    – Enigmativity
    Nov 23 '18 at 1:39
















-3















How do I assign one set of array values with another array's values? Both have 26 values.



I'm emulating a Deal or No Deal game where the user chooses a case from a specified list. Now, on each run of the console app I want there to be a random assignment for each cash prize to each case (for fairness sakes). My code is of the following:



    int cashPrizeArray = new int { 0, 1, 2, 5, 10, 20, 50, 100, 150, 200, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 10000, 15000, 20000, 25000, 50000, 75000, 100000, 200000 };
string caseArray = new string { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26" };

Console.WriteLine("Deal or Not!");
Console.Write("Choose a case: 1-26: ");
string userCase = Console.ReadLine();



if (!caseArray.Contains(userCase))
{
Console.WriteLine("nUnexpected input text.nThis application will now be terminated.nPress ENTER to continue...");
Console.ReadLine();
Environment.Exit(0);
}

else
{
Console.WriteLine("You chose case " + userCase);
Console.ReadLine();
}


I will need to reference these cases one by one when a user chooses them, and then remove them from being called in the array once initially opened.










share|improve this question




















  • 1





    And you have a question?

    – Enigmativity
    Nov 23 '18 at 1:28






  • 2





    Search for shuffle c# dozens and dozens of answers here ready and waiting for you to find them

    – None of the Above
    Nov 23 '18 at 1:30













  • @Enigmativity How do I assign one set of array values with another array's values? Both have 26 values.

    – kzone95
    Nov 23 '18 at 1:32











  • @kzone95: It's not clear to me what you even mean by "assign one set of array values with another array's values". So far your program has two arrays and accepts one input value from the user. Is something not working in that code? If your code is working and you're looking to move on to your next step, what is that step? Logically break down the problem into small and specific pieces. Which piece are you trying next? What have you tried?

    – David
    Nov 23 '18 at 1:35











  • Define a field in your class private static Random _rnd = new Random(); then on the line after you have defined cashPrizeArray put this: cashPrizeArray = cashPrizeArray.OrderBy(x => _rnd.Next()).ToArray();.

    – Enigmativity
    Nov 23 '18 at 1:39














-3












-3








-3








How do I assign one set of array values with another array's values? Both have 26 values.



I'm emulating a Deal or No Deal game where the user chooses a case from a specified list. Now, on each run of the console app I want there to be a random assignment for each cash prize to each case (for fairness sakes). My code is of the following:



    int cashPrizeArray = new int { 0, 1, 2, 5, 10, 20, 50, 100, 150, 200, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 10000, 15000, 20000, 25000, 50000, 75000, 100000, 200000 };
string caseArray = new string { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26" };

Console.WriteLine("Deal or Not!");
Console.Write("Choose a case: 1-26: ");
string userCase = Console.ReadLine();



if (!caseArray.Contains(userCase))
{
Console.WriteLine("nUnexpected input text.nThis application will now be terminated.nPress ENTER to continue...");
Console.ReadLine();
Environment.Exit(0);
}

else
{
Console.WriteLine("You chose case " + userCase);
Console.ReadLine();
}


I will need to reference these cases one by one when a user chooses them, and then remove them from being called in the array once initially opened.










share|improve this question
















How do I assign one set of array values with another array's values? Both have 26 values.



I'm emulating a Deal or No Deal game where the user chooses a case from a specified list. Now, on each run of the console app I want there to be a random assignment for each cash prize to each case (for fairness sakes). My code is of the following:



    int cashPrizeArray = new int { 0, 1, 2, 5, 10, 20, 50, 100, 150, 200, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 10000, 15000, 20000, 25000, 50000, 75000, 100000, 200000 };
string caseArray = new string { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26" };

Console.WriteLine("Deal or Not!");
Console.Write("Choose a case: 1-26: ");
string userCase = Console.ReadLine();



if (!caseArray.Contains(userCase))
{
Console.WriteLine("nUnexpected input text.nThis application will now be terminated.nPress ENTER to continue...");
Console.ReadLine();
Environment.Exit(0);
}

else
{
Console.WriteLine("You chose case " + userCase);
Console.ReadLine();
}


I will need to reference these cases one by one when a user chooses them, and then remove them from being called in the array once initially opened.







c# arrays list random






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 1:32







kzone95

















asked Nov 23 '18 at 1:26









kzone95kzone95

114




114








  • 1





    And you have a question?

    – Enigmativity
    Nov 23 '18 at 1:28






  • 2





    Search for shuffle c# dozens and dozens of answers here ready and waiting for you to find them

    – None of the Above
    Nov 23 '18 at 1:30













  • @Enigmativity How do I assign one set of array values with another array's values? Both have 26 values.

    – kzone95
    Nov 23 '18 at 1:32











  • @kzone95: It's not clear to me what you even mean by "assign one set of array values with another array's values". So far your program has two arrays and accepts one input value from the user. Is something not working in that code? If your code is working and you're looking to move on to your next step, what is that step? Logically break down the problem into small and specific pieces. Which piece are you trying next? What have you tried?

    – David
    Nov 23 '18 at 1:35











  • Define a field in your class private static Random _rnd = new Random(); then on the line after you have defined cashPrizeArray put this: cashPrizeArray = cashPrizeArray.OrderBy(x => _rnd.Next()).ToArray();.

    – Enigmativity
    Nov 23 '18 at 1:39














  • 1





    And you have a question?

    – Enigmativity
    Nov 23 '18 at 1:28






  • 2





    Search for shuffle c# dozens and dozens of answers here ready and waiting for you to find them

    – None of the Above
    Nov 23 '18 at 1:30













  • @Enigmativity How do I assign one set of array values with another array's values? Both have 26 values.

    – kzone95
    Nov 23 '18 at 1:32











  • @kzone95: It's not clear to me what you even mean by "assign one set of array values with another array's values". So far your program has two arrays and accepts one input value from the user. Is something not working in that code? If your code is working and you're looking to move on to your next step, what is that step? Logically break down the problem into small and specific pieces. Which piece are you trying next? What have you tried?

    – David
    Nov 23 '18 at 1:35











  • Define a field in your class private static Random _rnd = new Random(); then on the line after you have defined cashPrizeArray put this: cashPrizeArray = cashPrizeArray.OrderBy(x => _rnd.Next()).ToArray();.

    – Enigmativity
    Nov 23 '18 at 1:39








1




1





And you have a question?

– Enigmativity
Nov 23 '18 at 1:28





And you have a question?

– Enigmativity
Nov 23 '18 at 1:28




2




2





Search for shuffle c# dozens and dozens of answers here ready and waiting for you to find them

– None of the Above
Nov 23 '18 at 1:30







Search for shuffle c# dozens and dozens of answers here ready and waiting for you to find them

– None of the Above
Nov 23 '18 at 1:30















@Enigmativity How do I assign one set of array values with another array's values? Both have 26 values.

– kzone95
Nov 23 '18 at 1:32





@Enigmativity How do I assign one set of array values with another array's values? Both have 26 values.

– kzone95
Nov 23 '18 at 1:32













@kzone95: It's not clear to me what you even mean by "assign one set of array values with another array's values". So far your program has two arrays and accepts one input value from the user. Is something not working in that code? If your code is working and you're looking to move on to your next step, what is that step? Logically break down the problem into small and specific pieces. Which piece are you trying next? What have you tried?

– David
Nov 23 '18 at 1:35





@kzone95: It's not clear to me what you even mean by "assign one set of array values with another array's values". So far your program has two arrays and accepts one input value from the user. Is something not working in that code? If your code is working and you're looking to move on to your next step, what is that step? Logically break down the problem into small and specific pieces. Which piece are you trying next? What have you tried?

– David
Nov 23 '18 at 1:35













Define a field in your class private static Random _rnd = new Random(); then on the line after you have defined cashPrizeArray put this: cashPrizeArray = cashPrizeArray.OrderBy(x => _rnd.Next()).ToArray();.

– Enigmativity
Nov 23 '18 at 1:39





Define a field in your class private static Random _rnd = new Random(); then on the line after you have defined cashPrizeArray put this: cashPrizeArray = cashPrizeArray.OrderBy(x => _rnd.Next()).ToArray();.

– Enigmativity
Nov 23 '18 at 1:39












1 Answer
1






active

oldest

votes


















0














If you make a 2D list with the first dimension showing what case and the second dimension showing the amount of money for that amount of money. Then you check if you already have
used that specific case and if so then try again(used goto but you can change) or if it hasn't been used then you add that case into the list along with the money in the second dimension.



Code:



public static List<List<string>> PairedCases = new List<List<string>>();

public static void addsubstrin(string money, string casenom)
{
List<string> sublist = new List<string>();

sublist.Add(money);
sublist.Add(casenom);

PairedCases.Add(sublist);
}

static void Main(string args)
{
int cashPrizeArray = new int { 0, 1, 2, 5, 10, 20, 50, 100, 150, 200, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 10000, 15000, 20000, 25000, 50000, 75000, 100000, 200000 };
string caseArray = new string { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26" };

Random rnd = new Random();

foreach (int inte in cashPrizeArray)
{
Restart:;

int putincase = rnd.Next(1, 27);

bool found = false;

//here we chack if its already in the list

for (int a = 0; a < PairedCases.Count(); a++)
{
if (putincase.ToString() == PairedCases[a][1])
{
found = true;
}
}

if(found == false)
{
addsubstrin(inte.ToString(), putincase.ToString());
}
else
{
goto Restart;
}
}

for (int i = 0; i < PairedCases.Count(); i++)
{
Console.WriteLine(PairedCases[i][0] + " " + PairedCases[i][1]);
}

Console.ReadLine();
}





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439667%2frandomly-assign-array-value-with-another-arrays-value%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    If you make a 2D list with the first dimension showing what case and the second dimension showing the amount of money for that amount of money. Then you check if you already have
    used that specific case and if so then try again(used goto but you can change) or if it hasn't been used then you add that case into the list along with the money in the second dimension.



    Code:



    public static List<List<string>> PairedCases = new List<List<string>>();

    public static void addsubstrin(string money, string casenom)
    {
    List<string> sublist = new List<string>();

    sublist.Add(money);
    sublist.Add(casenom);

    PairedCases.Add(sublist);
    }

    static void Main(string args)
    {
    int cashPrizeArray = new int { 0, 1, 2, 5, 10, 20, 50, 100, 150, 200, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 10000, 15000, 20000, 25000, 50000, 75000, 100000, 200000 };
    string caseArray = new string { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26" };

    Random rnd = new Random();

    foreach (int inte in cashPrizeArray)
    {
    Restart:;

    int putincase = rnd.Next(1, 27);

    bool found = false;

    //here we chack if its already in the list

    for (int a = 0; a < PairedCases.Count(); a++)
    {
    if (putincase.ToString() == PairedCases[a][1])
    {
    found = true;
    }
    }

    if(found == false)
    {
    addsubstrin(inte.ToString(), putincase.ToString());
    }
    else
    {
    goto Restart;
    }
    }

    for (int i = 0; i < PairedCases.Count(); i++)
    {
    Console.WriteLine(PairedCases[i][0] + " " + PairedCases[i][1]);
    }

    Console.ReadLine();
    }





    share|improve this answer




























      0














      If you make a 2D list with the first dimension showing what case and the second dimension showing the amount of money for that amount of money. Then you check if you already have
      used that specific case and if so then try again(used goto but you can change) or if it hasn't been used then you add that case into the list along with the money in the second dimension.



      Code:



      public static List<List<string>> PairedCases = new List<List<string>>();

      public static void addsubstrin(string money, string casenom)
      {
      List<string> sublist = new List<string>();

      sublist.Add(money);
      sublist.Add(casenom);

      PairedCases.Add(sublist);
      }

      static void Main(string args)
      {
      int cashPrizeArray = new int { 0, 1, 2, 5, 10, 20, 50, 100, 150, 200, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 10000, 15000, 20000, 25000, 50000, 75000, 100000, 200000 };
      string caseArray = new string { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26" };

      Random rnd = new Random();

      foreach (int inte in cashPrizeArray)
      {
      Restart:;

      int putincase = rnd.Next(1, 27);

      bool found = false;

      //here we chack if its already in the list

      for (int a = 0; a < PairedCases.Count(); a++)
      {
      if (putincase.ToString() == PairedCases[a][1])
      {
      found = true;
      }
      }

      if(found == false)
      {
      addsubstrin(inte.ToString(), putincase.ToString());
      }
      else
      {
      goto Restart;
      }
      }

      for (int i = 0; i < PairedCases.Count(); i++)
      {
      Console.WriteLine(PairedCases[i][0] + " " + PairedCases[i][1]);
      }

      Console.ReadLine();
      }





      share|improve this answer


























        0












        0








        0







        If you make a 2D list with the first dimension showing what case and the second dimension showing the amount of money for that amount of money. Then you check if you already have
        used that specific case and if so then try again(used goto but you can change) or if it hasn't been used then you add that case into the list along with the money in the second dimension.



        Code:



        public static List<List<string>> PairedCases = new List<List<string>>();

        public static void addsubstrin(string money, string casenom)
        {
        List<string> sublist = new List<string>();

        sublist.Add(money);
        sublist.Add(casenom);

        PairedCases.Add(sublist);
        }

        static void Main(string args)
        {
        int cashPrizeArray = new int { 0, 1, 2, 5, 10, 20, 50, 100, 150, 200, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 10000, 15000, 20000, 25000, 50000, 75000, 100000, 200000 };
        string caseArray = new string { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26" };

        Random rnd = new Random();

        foreach (int inte in cashPrizeArray)
        {
        Restart:;

        int putincase = rnd.Next(1, 27);

        bool found = false;

        //here we chack if its already in the list

        for (int a = 0; a < PairedCases.Count(); a++)
        {
        if (putincase.ToString() == PairedCases[a][1])
        {
        found = true;
        }
        }

        if(found == false)
        {
        addsubstrin(inte.ToString(), putincase.ToString());
        }
        else
        {
        goto Restart;
        }
        }

        for (int i = 0; i < PairedCases.Count(); i++)
        {
        Console.WriteLine(PairedCases[i][0] + " " + PairedCases[i][1]);
        }

        Console.ReadLine();
        }





        share|improve this answer













        If you make a 2D list with the first dimension showing what case and the second dimension showing the amount of money for that amount of money. Then you check if you already have
        used that specific case and if so then try again(used goto but you can change) or if it hasn't been used then you add that case into the list along with the money in the second dimension.



        Code:



        public static List<List<string>> PairedCases = new List<List<string>>();

        public static void addsubstrin(string money, string casenom)
        {
        List<string> sublist = new List<string>();

        sublist.Add(money);
        sublist.Add(casenom);

        PairedCases.Add(sublist);
        }

        static void Main(string args)
        {
        int cashPrizeArray = new int { 0, 1, 2, 5, 10, 20, 50, 100, 150, 200, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 10000, 15000, 20000, 25000, 50000, 75000, 100000, 200000 };
        string caseArray = new string { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26" };

        Random rnd = new Random();

        foreach (int inte in cashPrizeArray)
        {
        Restart:;

        int putincase = rnd.Next(1, 27);

        bool found = false;

        //here we chack if its already in the list

        for (int a = 0; a < PairedCases.Count(); a++)
        {
        if (putincase.ToString() == PairedCases[a][1])
        {
        found = true;
        }
        }

        if(found == false)
        {
        addsubstrin(inte.ToString(), putincase.ToString());
        }
        else
        {
        goto Restart;
        }
        }

        for (int i = 0; i < PairedCases.Count(); i++)
        {
        Console.WriteLine(PairedCases[i][0] + " " + PairedCases[i][1]);
        }

        Console.ReadLine();
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 3:46









        Code ChapterCode Chapter

        36




        36






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439667%2frandomly-assign-array-value-with-another-arrays-value%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Wiesbaden

            Marschland

            Dieringhausen