Answered step by step
Verified Expert Solution
Question
1 Approved Answer
LC - 3 : Random Number Generator ( 5 0 points ) Random numbers are an important concept in computer science because they are often
LC: Random Number Generator points Random numbers are an important concept in computer science because they are often used to simulate realworld events. For example, in a game of chance, random numbers are used to determine the outcome of the game. In a computer simulation, random numbers are used to model the uncertainty of the system being simulated. Additionally, random numbers are used in many security applications, such as generating secure cryptographic keys and simulating user behaviour for testing purposes. Overall, the ability to generate random numbers allows computers to model and analyse complex, uncertain systems, making them a fundamental tool in computer science. However, computers cant just randomly generate numbers. They can make use of events of nature that appear to be random or at least, infeasibly hard to trace a pattern but what also happens regularly is that they use socalled pseudorandom number generators. An example of such a pseudorandom number generator where each number can be defined from the previous number can be seen in Equation given the three nonnegative integers a b and m Xn aXn b mod m Computer Architecture Homework Lastly, we need to define the initial number, X For this, computers usually take some noise, like the current time, but for your case, we will provide you with some artificial noise in the form of a few random characters or maybe a few dozen Another name for this initial number X is the seed. Input Details The first line of the input consists of three nonnegative integer numbers a b and m; these are represented using the normal decimal system. Note that these numbers are separatedsurrounded by spaces or new lines, therefore the inputs and and are all valid, equivalent inputs. After the three numbers a b and m have been read, there will be a line break followed by any number of characters, which will represent the seed X For each character, treat letters as their index in the alphabet starting from and digits like numbers. All other characters can and should be ignored. In other words, you may treat these as The sequence of characters ends with a new line. Note that there is no new line in the seed line. As an example, if we have the seed da we can deduce the following: d a The seed X is then obtained by taking the sum of all the valid characters. In our example, we have Example noise could be: abbH sa d or a The final line of the input will contain a nonnegative integer n represented using decimal notation which you should use to print X X Xn separated by a single new line. You should not print X So if the input is for example Computer Architecture Homework you should print X X X These numbers must be printed in hexadecimal form, and they must start with an x You should use capital letters and not print any leading zeroes. For example, instead of xdf you should print xDF Moreover, be sure to print a new line after the last number Xn as well! InputOutput Example Input aaabbbccc should print the output x x x x In this case, we see that a b m and the seed X equals X Since n we print X X X X and print a new line character after each. In a real application, the user would like to see what they type. Therefore, you must also print every inputted character. This is easily accomplished by using the OUT instruction after every GETC. Notice that you should not use the IN command because then you get the Input a character message each time, which is obviously undesirable. Implementation Hints You have learned about subroutines in the tutorial. They can make your journey much more pleasant, so consider using them. Also make sure document the subroutines for clarity. A simple LC template containing a subroutine is given below: Computer Architecture Homework ORIG x MAIN LD R MODULOROUTINEPTR JSRR R HALT ; data MODULOROUTINEPTR FILL MODULOROUTINE ENDMAIN ; ; Description: does a thing ; parameters: R: contains something ; R: contains something else ; post condition: R: contains something else else ; MODULOROUTINE ; RET ; data ENDMODULOROUTINE END Lastly, dont forget that your LC programs must always start with ORIG x
LC: Random Number Generator points
Random numbers are an important concept in computer science because they are often used
to simulate realworld events. For example, in a game of chance, random numbers are used to
determine the outcome of the game. In a computer simulation, random numbers are used to model
the uncertainty of the system being simulated. Additionally, random numbers are used in many
security applications, such as generating secure cryptographic keys and simulating user behaviour
for testing purposes. Overall, the ability to generate random numbers allows computers to model
and analyse complex, uncertain systems, making them a fundamental tool in computer science.
However, computers cant just randomly generate numbers. They can make use of events of nature
that appear to be random or at least, infeasibly hard to trace a pattern but what also happens
regularly is that they use socalled pseudorandom number generators. An example of such a
pseudorandom number generator where each number can be defined from the previous number can
be seen in Equation given the three nonnegative integers a b and m
Xn aXn b mod m
Computer Architecture Homework
Lastly, we need to define the initial number, X For this, computers usually take some noise, like
the current time, but for your case, we will provide you with some artificial noise in the form of a
few random characters or maybe a few dozen Another name for this initial number X is the seed.
Input Details
The first line of the input consists of three nonnegative integer numbers a b and m; these are
represented using the normal decimal system. Note that these numbers are separatedsurrounded
by spaces or new lines, therefore the inputs
and
and
are all valid, equivalent inputs.
After the three numbers a b and m have been read, there will be a line break followed by any
number of characters, which will represent the seed X For each character, treat letters as their
index in the alphabet starting from and digits like numbers. All other characters can and
should be ignored. In other words, you may treat these as The sequence of characters ends with
a new line. Note that there is no new line in the seed line. As an example, if we have the seed
da we can deduce the following:
d a
The seed X is then obtained by taking the sum of all the valid characters. In our example, we have
Example noise could be:
abbH sa d
or
a
The final line of the input will contain a nonnegative integer n represented using decimal notation
which you should use to print X X Xn separated by a single new line. You should not
print X So if the input is for example
Computer Architecture Homework
you should print
X
X
X
These numbers must be printed in hexadecimal form, and they must start with an x You should
use capital letters and not print any leading zeroes. For example, instead of xdf you should
print xDF
Moreover, be sure to print a new line after the last number Xn as well!
InputOutput Example
Input
aaabbbccc
should print the output
x
x
x
x
In this case, we see that a b m and the seed X equals X
Since n we print X X X X and print a new line character after
each.
In a real application, the user would like to see what they type. Therefore, you must also print
every inputted character. This is easily accomplished by using the OUT instruction after every GETC.
Notice that you should not use the IN command because then you get the Input a character
message each time, which is obviously undesirable.
Implementation Hints
You have learned about subroutines in the tutorial. They can make your journey much more
pleasant, so consider using them. Also make sure document the subroutines for clarity. A simple
LC template containing a subroutine is given below:
Computer Architecture Homework
ORIG x
MAIN
LD R MODULOROUTINEPTR
JSRR R
HALT
; data
MODULOROUTINEPTR FILL MODULOROUTINE
ENDMAIN
;
; Description: does a thing
; parameters: R: contains something
; R: contains something else
; post condition: R: contains something else else
;
MODULOROUTINE
;
RET
; data
ENDMODULOROUTINE
END
Lastly, dont forget that your LC programs must always start with ORIG x
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started