Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Function Name: genRandomIntArr
- * Description: Generates an array of integers based on the inputs given
- * Inputs:
- * Int size - The amount of numbers that should be in the integer array
- * Int min - The minimum value each generated number can be
- * Int max - The maximum value each generated number can be
- * Function Outputs:
- * Int[] numArr - An array of integers
- */
- //Use Private Static ReadOnly Variable as it Prevents generating same number set repeatedly
- //each random is initialized using the clock, if we init several new ones at same time we get same number result
- //so we just init one and use rand.next to make sure we get unique number sets each time!
- private static readonly Random random = new Random();
- //The function itself!
- static int[] genRandomIntArr(int size, int min, int max)
- {
- //Create num array using size input
- int[] numArr = new int[size - 1];
- //For 0 to size given as input - 1 aka if size is 3 then fill array slots 0, 1, and 2
- for (int j = 0; j < (size - 1); j++)
- {
- //Generate number to add using min and max from input
- int randNum = random.Next(min, max);
- //Add number to numArr
- numArr[j] = randNum;
- }
- //Return result
- return numArr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement