Question: Java Random numbers are useful for lots of different programming tasks, including gaming, simulation, etc. Java API provides a Random class that you can use

Java

Random numbers are useful for lots of different programming tasks, including gaming, simulation, etc. Java API provides a Random class that you can use to generate random numbers. To use Random class to generate random integers, follow these steps:

This class is part of the java.util package, so any program that uses it will need an import statement such as: import java.util.Random;

Create an object from the Random class with: Random random = new Random();

Call the nextInt() method or nextInt(int n) method to generate a random integer. For example:

int number = random.nextInt(); //number can be any integer in the range of an int type.

int number = random.nextInt(100);//number can be somewhere between 0 and 99.

In this activity, work with your team to define a method that takes an integer parameter n and returns an integer array of length n. The method generates n unique random numbers, with each number between 0 and n-1. These numbers are stored in an array, which is returned by the method. For example, if the method input is 4, then a possible return value can be {0, 3, 2, 1}. Note that each element in the array is unique.

Work with your team to complete the following:

1. On paper, write pseudocode instructions to solve the problem.

2. Implement your pseudocode in zyBook section 17.2.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!