Discover the answers you need at Westonci.ca, a dynamic Q&A platform where knowledge is shared freely by a community of experts. Discover solutions to your questions from experienced professionals across multiple fields on our comprehensive Q&A platform. Get precise and detailed answers to your questions from a knowledgeable community of experts on our Q&A platform.
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)+"%");
}
Thank you for visiting our platform. We hope you found the answers you were looking for. Come back anytime you need more information. We hope this was helpful. Please come back whenever you need more information or answers to your queries. Your questions are important to us at Westonci.ca. Visit again for expert answers and reliable information.