Question

Please use the algorithm to generate 1000 random numbers in JAVA. (Print every 50th)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Explanation:

Below is the Java code for above problem with proper description provided within comments itself. Below code some sample output screenshots are attached.

Java code :

import java.util.Random;

public class RrandomAlgorithm {

        public static int[] algorithm(int n) {
                // real array
                int real[] = new int[n + 1];
                // integer array
                int integerArray[] = new int[n+1];

                for (int i = 0; i < n; i++) {
                        // store random numbers
                        integerArray[i] = new Random().nextInt(n - 1) + 1;
                }

                // loop to apply algorithm
                for (int i = 1; i <= n; i++) {
                        // remainder when 7^5*li is divided by 2^31-1
                        integerArray[i] = (int) ((Math.pow(7, 5) * integerArray[i - 1]) % Integer.MAX_VALUE);
                        // li/2^31-1
                        real[i] = integerArray[i] % Integer.MAX_VALUE;
                }
                // return result
                return real;
        }

        public static void main(String[] args) {
                // TODO Auto-generated method stub
                // call the algorithm
                int res[] = algorithm(1000);

                // print the numbers
                System.out.println("Random Numbers Every 50th : ");
                for (int i = 1; i < res.length; i = i + 50)
                        System.out.print("\n" + res[i]);
        }

}

Sample Output :

D RrandomAlgorithm.java PL Problems曰Console × | @ Javadoc Q. Declara 1 import java.util.Random; 2 3 public class RrandomAlgor

Add a comment
Know the answer?
Add Answer to:
Please use the algorithm to generate 1000 random numbers in JAVA. (Print every 50th) integer array...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Write a C code that do the following: Generate array of random integer numbers of...

    1. Write a C code that do the following: Generate array of random integer numbers of size 25 Fill the array with random integers ranging from [1-100] Find the maximum number of the array and its location Find the minimum number of the array and its location Search for a number in the array Print the array Flip the array Sort this array Quit the program when the user choose to exit

  • Java 1. Create a 1D array of 4096 Unique random integer numbers of 1 to 5...

    Java 1. Create a 1D array of 4096 Unique random integer numbers of 1 to 5 digits. Of those numbers give me the following information: - Mean , Mode, Median, Range. - Five times, ask the user for a number within the range (from above) and record the time to find the number in the range. (Loop count) 2. Using a any sort algorithm, build sorted 2D array of random numbers (1 TO 5 digits ) with the x direction...

  • Please help me with this algorithm assignment using Java Write 2 functions to calculate the MSS...

    Please help me with this algorithm assignment using Java Write 2 functions to calculate the MSS of a given array one with running time of O(n) and one with O(nlogn) .Request the user to enter a positive integer, and call it n. 1.Generate n random integers between -100 to 100 and save them in array a. 2.Print the generated array and the outputsof your two functions

  • This is java. Please let me know about those code. Please do not use array and...

    This is java. Please let me know about those code. Please do not use array and scanner. Just do by loop. // a) Task: Find the sum of all multiples of 3 and 5 less than 1000. // b) Task: Given two integers k and n, print out every multiple of k less than n // c) Task: Given an integer n, print out k^k for every k=1...n // d) Task: Write a function called "factorProduct" that takes as input...

  • JAVA HELP: Directions Write a program that will create an array of random numbers and output...

    JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in);    System.out.println("Seed:"); int seed = scanner.nextInt();    System.out.println("Length"); int length = scanner.nextInt(); Random random...

  • 6. Consider the following algorithm, where P is an array containing random numbers. The function swap(v1,v2)...

    6. Consider the following algorithm, where P is an array containing random numbers. The function swap(v1,v2) will swap the values stored in the variables v1 and v2. Note that % is the modulus operation, and will return the integer remainder r of a/b, i.e., r-a%b Require: Array P with n > 0 values 1: i-1, j-n-l 2: while i<=j do for a=i to j by i do 4: 5: 6: 7: if Pla>Pat 11 and Pla]%2--0 then swap(Plal, Pla+1l) end...

  • Write a Java program with a single-dimension array that holds 11 integer numbers and sort the...

    Write a Java program with a single-dimension array that holds 11 integer numbers and sort the array using a bubble sort. Next, identify the median value of the 11 integers. Here are the steps your program must accomplish. algorithm (either flowchart or pseudocode) that you will use to write the program Step 1. Create an Place the algorithm in a Word document. 6. Ste the Step 2. Code the program in Eclipse and ensure the following steps are accomplished. 1....

  • Java Array The method rotateLeft() takes in a reference a to an integer array and a...

    Java Array The method rotateLeft() takes in a reference a to an integer array and a positive integer n and it returns a new array whose contents is the contents of the input array rotated to the left n places. So each element a[i] of the input array should be placed at location b[i-n] of the returned array. If the index i-n is negative, then that index should "wrap" around to the end of the output array. For example, if...

  • 1. Please write a Divide-and-Conquer Java algorithm solving the following problem: Given an "almost sorted" array...

    1. Please write a Divide-and-Conquer Java algorithm solving the following problem: Given an "almost sorted" array of distinct integers, and an integer x, return the index of x in the array. If the element x is not present in the array, return -1. "Almost sorted" means the following. Assume you had a sorted array A[0…N], and then split it into two pieces A[0…M] and A[M+1…N], and move the second piece upfront to get the following: A[M+1]…A[N]A[0]…A[M]. Thus, the "almost sorted"...

  • Java question Given an array of integer numbers, write a linear running time complexity program in...

    Java question Given an array of integer numbers, write a linear running time complexity program in Java to find the stability index in the given input array. For an array A consisting n integers elements, index i is a stability index in A itf ATO] + A[1] + +A[iI-1] Ali+1]+ Ali+2] +... + A[n-1]; where 0 <i< n-1 Similarly, 0 is an stability index if (A[1] A[2]A[n-1]) 0 and n-1 is an stability index if (A[0] A[1]+... A[n-21) 0 Example:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT