Explore Westonci.ca, the premier Q&A site that helps you find precise answers to your questions, no matter the topic. Connect with a community of experts ready to help you find accurate solutions to your questions quickly and efficiently. Experience the ease of finding precise answers to your questions from a knowledgeable community of experts.
Sagot :
Answer:
In Java:
import java.util.*;
public class RandomDistributionCheck{
public static void main(String[] args) {
final int iter = 10000000;
final int unique = 20;
Random rd = new Random();
int [] intArray = new int[20];
for(int i =0;i<20;i++){ intArray[i]=0; }
for(int i =0; i<iter; i++){
int rdd = rd.nextInt(20);
intArray[rdd]++; }
System.out.println("Number\t\tOccurrence\tPercentage");
for(int i =0;i<unique;i++){
System.out.println(i+"\t\t"+intArray[i]+"\t\t"+(intArray[i]/100000)+"%");
} } }
Explanation:
This declares the number of iteration as constant
final int iter = 10000000;
This declares the unique number as constant
final int unique = 20;
This creates a random object
Random rd = new Random();
This creates an array of 20 elements
int [] intArray = new int[20];
This initializes all elements of the array to 0
for(int i =0;i<20;i++){ intArray[i]=0; }
This iterates from 1 to iter
for(int i =0; i<iter; i++){
This generates a random number
int rdd = rd.nextInt(20);
This increments its number of occurrence
intArray[rdd]++; }
This prints the header
System.out.println("Number\t\tOccurrence\tPercentage");
This iterates through the array
for(int i =0;i<unique;i++){
This prints the required output
System.out.println(i+"\t\t"+intArray[i]+"\t\t"+(intArray[i]/100000)+"%");
}
We appreciate your time. Please revisit us for more reliable answers to any questions you may have. We appreciate your visit. Our platform is always here to offer accurate and reliable answers. Return anytime. Westonci.ca is committed to providing accurate answers. Come back soon for more trustworthy information.