This code is a simple array that contains random integers between 1 through 5.
It may seem a little obvious, but this code is useful for testing random arrays. It can be used to randomly choose an array, add some numbers, and test that the array wasn’t changed by the application of a new number. It may seem a little obscure, but it’s also a fun way to try out random array usage.
Another fun use of the array is to use it as a way to test for any kinds of changes. For example, if you have a large array whose values are each incremented by 10 each time, you could set a breakpoint in the code so that you could see if the array was changed from the previous iteration or not.
Not to worry. Array.Random is simply a class that generates arrays of random values. The interesting thing is that the array is never actually changed. And we have a simple test that will return true if the value is changed, and false otherwise, so the array will always be the same as before.
So let’s create a test function that will test the random array with one or more arrays that have different values. We’ll use these arrays to create a new array and then use this array in a loop to see if we find a pattern.
If you want to use looping constructs without using the new keyword, you can use a do-while loop. Inside of a do-while loop, if you want to jump to a certain line in a for loop, you can do so by using switch/case statement.
A very nice way to make a “for loop” without the looping construct itself working is by using a do-while loop.