Madison E.
asked 01/15/23Python3 Programming Problem
Write a program that takes two integer values a,n
as command line arguments separated by spaces. The arguments denote a range [0,a-1]
and a modulus n
. Your program should generate 10000 random numbers between 0
and a-1
(inclusive), applies a modulo n
and prints out a list of the number of times each possible number 0..a-1
appeared, one number on each line. To check your work, if a=6
and you use a modulus of n=3
, you should get all the results equally likely (roughly) but if n=5
you will not.
Hi there, I need help breaking down this coding problem and what it is asking
2 Answers By Expert Tutors
Judy R. answered 01/22/23
Hello I am 22 years experienced Online Tutor and Assignment Helper for Computer Science and Math. I have been teaching IT Professionals, students from different grades, and Graduate and Post Graduate students for more than 22 years. I am ready to help you with your learning requirements, assignments, tests, and projects. For further discussion about the assignment or project help you need, please add me on skype and my skype id is nettuitions Thanks

Bradley T. answered 01/15/23
Tutor for Python and High School and Middle School Math
We are given two numbers, a and n.
- Using the example they give, you would need to generate 10,000 numbers between 0 and 6. For example [5,2,0,4....] .
- For each number, you need to take the modulus (the % operator in python). A modulus is the remainder we get from dividing one number by another. For example using a modulus of 3:
- 5/3 = 1r2 so 5 mod 3 or 5%3 = 2
- 2/3 = 0r2 so 2%3 = 2
- 0/3 = 0r0 so 0%3 = 0
- 4/3 = 1r1 so 4%3 = 1
- We take the mod and find the remainders of all the randomly generated numbers. The mod operator will always give an answer that is less than the divisor. So if we do modulus 3, our answers can only be 0 or 1 or 2. We count how many of each we got, that is our answer.
- To explain a little bit more about the final sentence of the problem, the mod operator cycles through numbers. A quick example: 0%2 = 0 , 1%2 = 1, 2%2 = 0, 3%2 = 1. and the answer cycles between 0 and 1 when we take modulus 2. So when we take the modulus of numbers that evenly divide, we except a complete cycle. If we randomly take all the numbers below 6(0 to 5) and take mod 3, the answer is 0, 1 and 2 1/3 of the time each. If we use number that aren't evenly divisible, we can't complete the cycle of remainders ie all numbers below 6(0 to 5) mod 5 will give us an answer of 0 two times, and 1,2,3,4,5 one time each. Once we do this experiment many many times, you can expect that the answer 0 will appear 2/6 of the time, while the rest only appear about 1/6 of the time each.
tldr: You need to create a program that is able to randomly select numbers within a certain range. Then take the modulus of all those numbers. Then count how many times you got each answer. The final counts is the solution
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Judy R.
Hello I am 22 years experienced Online Tutor and Assignment Helper for Computer Science and Math. I have been teaching IT Professionals, students from different grades, and Graduate and Post Graduate students for more than 22 years. I am ready to help you with your learning requirements, assignments, tests, and projects. For further discussion about the assignment or project help you need, please add me on skype and my skype id is nettuitions Thanks01/22/23