Pseudorandom Number generation:
In Java, there is a built-in class java.util.Random whose object as pseudorandom number to determine the sequence of numbers by randomly.
Note: Refer page number 113 to formula for next pseudorandom number in the text book.
According the formula given by the text book, the current seed “cur” value is needed to find the next pseudorandom number. But, here the only one current seed “cur” is given to find the five next pseudorandom numbers.
- Apply the given inputs for five times; get the same next pseudorandom number. So, take current seed value as “next pseudorandom number” to find the next pseudorandom numbers.
Explanation of Solution
Determine the next five pseudorandom numbers:
The given inputs are,
a = 12
b = 5
n = 100
Current seed (cur) = 92
The formula for next pseudorandom number is given below:
First pseudorandom numbers:
Substitute the “a”, “b”, “n”, and “cur” in the Equation (1) to determine the first next pseudorandom number is given below:
Therefore, the first pseudorandom number for current seed (cur = 92) is 9.
Second pseudorandom numbers:
Here, let us consider the current seed “cur” as “9”. That is, result of first pseudorandom number.
Substitute the “a”, “b”, “n”, and “cur” in the Equation (1) to determine the first next pseudorandom number is given below:
Therefore, the second pseudorandom number for current seed (cur = 9) is 13.
Third pseudorandom numbers:
Here, let us consider the current seed “cur” as “13”. That is, result of second pseudorandom number.
Substitute the “a”, “b”, “n”, and “cur” in the Equation (1) to determine the first next pseudorandom number is given below:
Therefore, the third pseudorandom number for current seed (cur = 13) is 61.
Fourth pseudorandom numbers:
Here, let us consider the current seed “cur” as “61”. That is, result of second pseudorandom number.
Substitute the “a”, “b”, “n”, and “cur” in the Equation (1) to determine the first next pseudorandom number is given below:
Therefore, the fourth pseudorandom number for current seed (cur = 61) is 37.
Fifth pseudorandom numbers:
Here, let us consider the current seed “cur” as “37”. That is, result of second pseudorandom number.
Substitute the “a”, “b”, “n”, and “cur” in the Equation (1) to determine the first next pseudorandom number is given below:
Therefore, the fourth pseudorandom number for current seed (cur = 37) is 49.
Want to see more full solutions like this?
Chapter 3 Solutions
Data Structures and Algorithms in Java
- decided to write an infinite sequence. Initially, he wrote 00, and then he started repeating the following process: Look at the last element written so far (the ll-th element if the sequence has length ll so far); let's denote it by xx. If xx does not occur anywhere earlier in the sequence, the next element in the sequence is 00. Otherwise, look at the previous occurrence of xx in the sequence, i.e. the kk-th element, where k<lk<l, this element is equal to xx and all elements between the k+1k+1-th and l−1l−1-th are different from xx. The next element is l−kl−k, i.e. the distance between the last two occurrences of xx. The resulting sequence is (0,0,1,0,2,0,2,2,1,…)(0,0,1,0,2,0,2,2,1,…): the second element is 00 since 00 occurs only once in the sequence (0)(0), the third element is 11 since the distance between the two occurrences of 00 in the sequence (0,0)(0,0) is 11, the fourth element is 00 since 11 occurs only once in the sequence (0,0,1)(0,0,1), and so on. Chef has given…arrow_forwardWhat is the count of positive and negative charges in the amino acid sequence “YEVHHQKLVFFAEDVGSNKGAIIGLMVGGVV”? (Solve this using Python; not by hand). Compute the transition matrix for the sequence in “dna.txt”. The transition matrix tells you the number of times you move from one nucleotide to another. For instance, in the sequence AATACGAT, AA occurs once, AT occurs twice, AC occurs once, TA occurs once, CG occurs once, GA occurs once, and all other combinations occur 0 times. Print out the transition matrix. (here imagine Dna.txt is a dna sequence file)arrow_forwardIf n is an integer, what are the common divisors of n and 1? What are thecommon divisors of n and 0?arrow_forward
- Write a C/C++ program to implement Floyd Warshall Algorithm that displays the matrix after each step. Elements should be right-aligned in proper columns. Use your program on the graph given below. Give the source code and the runtime screen. 3 8. 1 4 3 2.arrow_forwardThe word "cat" can be spelled from the period table element symbols by using the sequence of elements carbon and astatine in that order. Since the symbol for carbon is "C" and the symbol for astatine is "At", which together makes [C][At]; thus, "cat" is an elemental phrase. To determine which elements can be used all combinations of 1 and 2 letter element symbols must be tested. Write a java program to determine if a lowercase word can be made with any combination of 1 or 2 letter element symbols from the periodic table. The list elements will come from a text file containing all the atomic elements and their symbols. The user will enter a lowercase word to check for from the keyboard. Assume the word is properly spelled but check for all lowercase letters. Output to the screen the list of chemical elements if it can be made from the element symbols following the format as seen below, if not output: "No element phrase possible." Output all possible solutions if applicable. Finally, ask…arrow_forwardwrite a java program to swapping 4 numbers using array and method.arrow_forward
- Task is to generate a list of 100 random integers between 1 and 1000. The integers should be sorted from smallest to largest and have no duplicates. Your code should perform at most n operations, where n = 100 in this case. What this means is that your random generation function random.randint(x,y) should not be called more than 100 times.arrow_forwardWrite a java code for the following . Write a Java program to print the unique elements along with their frequency in the given (3x 3) integer matrix. ex. java sample outputarrow_forwardWrite a recursive implementation of Euclid’s algorithm for finding the greatest common divisor (GCD) of two integers. Descriptions of this algorithm are available in algebra books and on the Web. Write a test program that calls your GCD procedure five times, using the following pairs of integers: (5,20), (24,18), (11,7), (432,226), (26,13). After each procedure call, display the GCD.arrow_forward
- choose any number as n, output all n-digit binary numbers which have equal total in right and left halves. mid element can either be 1 or 0 IF n is odd. 1. Explain where does the recursion happened? 2. Solve using the programming languages and test. Input : n=4 output: 0000 0101 0110 1001 1010 1111arrow_forwardPlaying with capture operator in elixir language. Your task is to write a program with elixir with Capture operator to multiply two given numbersarrow_forwardComplex numbers create the Mandelbrot set, where each of those recursive sequence goes to 0. The sequence defined is: Zn = (Zn-1)2 + c Do research on numbers in the Mandelbrot set, and find a few numbers you can iterate to 0, showing the process.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education