0

I am trying to randomly select array values on another array avoiding duplicate but am getting an output that is out of my scope.

please help.

Here is my code below

 static Random rn = new Random();

 static void RandomGenerator()
 {
     String[] greatingsStyles = { "Hello", "Hay", "Morning", "Good day", "Howzit", "Sure" };
     String[] newGreatingsStyles = { };
     for (int j = 0; greatingsStyles.Length >j; j++)
     {
         String ranGreatingsStyles = greatingsStyles[rn.Next(5)];
         if (!greatingsStyles.Contains(ranGreatingsStyles))
         {
             newGreatingsStyles = newGreatingsStyles.Concat(new string[] { ranGreatingsStyles }).ToArray();
         }
     }
     foreach (int i in newGreatingsStyles.ToString())
     {
         Console.WriteLine(i);
     }
}
5
  • 1
    What output you are getting? What is your scope? Commented Jan 29, 2020 at 9:57
  • shuffle and gen n first ... Commented Jan 29, 2020 at 9:57
  • It sounds like a school assignment. So don't know if you can use this. I would shuffle the list and return the result. Take a look at the following StackOverFlow question: stackoverflow.com/questions/273313/randomize-a-listt Commented Jan 29, 2020 at 9:59
  • Why it has +1 ? question was already asked multiple times Commented Jan 29, 2020 at 10:03
  • Does newGreatingsStyles should contains all items of newGreatingsStyles? Commented Jan 29, 2020 at 10:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.