This code assumes that the array b contains at least as many elements as a . As an exercise, write a method called cloneArray that takes an array of integers as a parameter, creates a new array that is the same size, copies the elements from the first array into the new one, and then returns a reference to the new array. Most computer programs do the same thing every time they are executed, so they are said to be deterministic . Usually, determinism is a good thing, since we expect the same calculation to yield the same result. For some applications, though, we would like the computer to be unpredictable.
Games are an obvious example, but there are many more.
Making a program truly nondeterministic turns out to be not so easy, but there are ways to make it at least seem nondeterministic. One of them is to generate random numbers and use them to determine the outcome of the program. Java provides a built-in method that generates pseudorandom numbers, which are not truly random in the mathematical sense, but for our purposes, they will do. Check out the documentation of the random method in the Math class. The return value is a double between 0.0 and 1.0.