Requirements:

For this exercise, you are asked to write a method called InitializeArrayWithNoDuplicates(), using the provided method header below, which will return a one dimensional array in which every element is a randomly generated integer between 1 and 45 inclusive with no integer value occurring more than once in the array.

The length of the array is passed as a parameter to the method and you can assume that the parameter value will be less than 45 and greater than zero.

Use the Random class method int Next(int minValue, int maxValue) which returns a random integer which is greater than or equal to minValue and less than maxValue.

To enable you to test your code, you should create a Main() method that calls the InitializeArrayWithNoDuplicates() method several times with different parameters each time to show that the method is correct; similar to the Main() method of the linear search exercise in Week 4.

Include a simple DisplayArray() method similar to that in the linear search exercise to output the resultant array, called from Main().

Exactly what you do to test the method and display the array is not important for your AMS marks as only your InitializeArrayWithNoDuplicates() method will be run. This means it must be public.

using System;
namespace RandomArray
{
public class RandomArrayNoDuplicates
{
static Random rng = new Random();
/// < summary>
/// Creates an array with each element a unique integer
/// between 1 and 45 inclusively.
/// < /summary>
/// length of the returned array < 45
/// < /param>
/// < returns>an array of length "size" and each element is
/// a unique integer between 1 and 45 inclusive < /returns>
public static int[] InitializeArrayWithNoDuplicates(int size)
{
}
}
}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.