Question

In: Math

1. One method for obtaining random numbers is by Middle Square method, you are asked to...

1. One method for obtaining random numbers is by Middle Square method, you are asked to create an algorithm to get a random number with an 6 digit integer number. And give an example.

Solutions

Expert Solution

Here is the C++ code to generate random number using Middle Square method.

CODE:

#include <iostream>
#include <math.h>
#include <stdlib.h>

using namespace std;

int a[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000 };
int middleSquareNumber(int numb, int dig)
{
int sqn = numb * numb, next_num = 0;
int trim = (dig / 2);
sqn = sqn / a[trim];
for (int i = 0; i < dig; i++)
{
next_num += (sqn % (a[trim])) * (a[i]);
sqn = sqn / 10;
}
return next_num;
}

int main(int argc, char **argv)
{
cout << "Enter the #-digit random numbers you want: ";
int n;
cin >> n;
int start = 1, end = 1;

start = a[n - 1];
end = a[n];

int number = ((rand()) % (end - start)) + start;
cout << "The random numbers are:\n" << number << ", ";
for (int i = 1; i < n; i++)
{
number = middleSquareNumber(number, n);
cout << number << ", ";
}
cout << "...";
}

OUTPUT:

The random numbers are

100041,3254727,4575382,1349485,130861,-165727


Related Solutions

1. you learned that random numbers (or, at least, pseudorandom numbers) are essential in cryptography, but...
1. you learned that random numbers (or, at least, pseudorandom numbers) are essential in cryptography, but it is extremely difficult even for powerful hardware and software to generate them. Go online and conduct research on random number generators. What are the different uses of these tools besides cryptography? How do they work? Explain your answer using your own words in 4-5 paragraphs. 2 .Do you believe that all data should be encrypted? Many computing professionals think this is a good...
(1) Suppose a population numbers in the millions. If one takes a random sample from that...
(1) Suppose a population numbers in the millions. If one takes a random sample from that population of an appropriate size to meet normality assumptions, the mean of the sample will be the same as the mean of the population. Select one: a. always true b. always false c. may be true, but unlikely d. may be false, but unlikely (2) The mode of a probability distribution is the least likely outcome. Select one: a. TRUE b. FALSE (3) “I...
I am asked to find the square roots using the bisection method for x * x...
I am asked to find the square roots using the bisection method for x * x - a = 0. I was wondering how the bisection method is performed. Let's suppose a = 9, so I would need to find the roots of x * x - 9 = 0. Also, from the 1st equation, when would the bisection method NOT output a root?
In this activity, you will determine the probability of obtaining one of these disproportionate ratios if...
In this activity, you will determine the probability of obtaining one of these disproportionate ratios if we assume that nature alone is responsible for these obscure results. In order to determine these probabilities, you will use the Normal approximation to the binomial. 1. Outline the binomial model for the number of boy births in the next 1000 births assuming that births are produced according to the natural ratio of 51.2% chance of a boy. 2. Outline the Normal approximation to...
1) Question with methods use scanner: 1) Create one method that will add four numbers (return...
1) Question with methods use scanner: 1) Create one method that will add four numbers (return method or regular public static void ) 2) Create another method that will subtract four numbers (return method or regular public static void ) 3) Create another method that will multiplay four numbers (return method or regular public static void ) 4) Create another method that will divide four numbers (return method or regular public static void ) 5) Create another method that will...
how would you use randomly generated numbers to find 30 random numbers from 1 to 500?
how would you use randomly generated numbers to find 30 random numbers from 1 to 500?
180 students were asked to randomly pick one of the numbers 1, 2, 3, 4, 5,...
180 students were asked to randomly pick one of the numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. The number 7 was picked by 61 students. a) For the sample, calculate the proportion of students who picked 7. (Round the answer to three decimal places.) (b) Calculate the standard error for this sample proportion. (Round the answer to three decimal places.) (c) Calculate a 90% confidence interval for the population proportion. (Round the answer to three decimal...
210 students were asked to randomly pick one of the numbers 1, 2, 3, 4, 5,...
210 students were asked to randomly pick one of the numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. The number 7 was picked by 61 students. (c) Calculate a 90% confidence interval for the population proportion. (Round the answer to three decimal places.) ___________to ___________ (d) Calculate a 95% confidence interval for the population proportion. (Round the answer to three decimal places.) to   __________to____________ (e) Calculate a 98% confidence interval for the population proportion. (Round the answer...
You have been asked to participate on a committee charged with designing the ideal middle school....
You have been asked to participate on a committee charged with designing the ideal middle school. Given your knowledge of the developmental stages adolescents are traversing at this age, discuss three recommendations you would offer to promote the social, emotional, and academic development of the students and the rationale for each recommendation. (detailed answer please)
9) Create a java programming where you will enter two numbers and create only one method,...
9) Create a java programming where you will enter two numbers and create only one method, which will return or display addition, substraction, multiplication, division, average and check which number is greater than the other. Everything in one method and call it in main method.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT