Answered step by step
Verified Expert Solution
Link Copied!

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-3: Random Number Generator (50 points)
Random numbers are an important concept in computer science because they are often used
to simulate real-world 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 so-called pseudo-random number generators. An example of such a
pseudo-random number generator where each number can be defined from the previous number can
be seen in Equation 1, given the three non-negative integers a, b, and m.
Xn =(aXn1+ b) mod m (1)
3
Computer Architecture Homework 5
Lastly, we need to define the initial number, X0. 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 X0 is the seed.
Input Details
The first line of the input consists of three non-negative integer numbers a, b and m; these are
represented using the normal decimal system. Note that these numbers are separated/surrounded
by spaces or new lines, therefore the inputs
1234
and
12
3
4
and
12
34
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 X0. For each character, treat letters as their
index in the alphabet (starting from 0), and digits like numbers. All other characters can (and
should) be ignored. In other words, you may treat these as 0. 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
,9d23a569.,, we can deduce the following:
,9 d 23 a 569.,
----------------------
09323056900
The seed X0 is then obtained by taking the sum of all the valid characters. In our example, we have
0+9+3+2+3+0+5+6+9+0+0=37.
Example noise could be:
abbH23 sa ^^651d
or
5663a
The final line of the input will contain a non-negative integer n (represented using decimal notation),
which you should use to print X1, X2,..., Xn separated by a single new line. You should not
print X0! So if the input is, for example
3
4
Computer Architecture Homework 5
you should print
X_1
X_2
X_3
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 x00d5f you should
print xD5F.
Moreover, be sure to print a new line after the last number Xn as well!
Input/Output Example
Input
2325
aaabbbccc^^1
4
should print the output
x17
x18
x1
x5
In this case, we see that a =2, b =3, m =25, and the seed X0 equals 10(X0=0+0+0+1+1+
1+2+2+2+1=10). Since n =4, we print X1, X2, X3, X4 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
LC3 template containing a subroutine is given below:
5
Computer Architecture Homework 5
.ORIG x3000
MAIN
LD R2, MODULO_ROUTINE_PTR
JSRR R2
HALT
; data
MODULO_ROUTINE_PTR .FILL MODULO_ROUTINE
END_MAIN
;=====================================================
; Description: does a thing
; - parameters: R1: contains something
; R2: contains something else
; - post condition: R4: contains something else else
;=====================================================
MODULO_ROUTINE
;
RET
; data
END_MODULO_ROUTINE
.END
Lastly, dont forget that your LC-3 programs must always start with .ORIG x3000.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Why is job analysis considered to be a basic HR tool?

Answered: 1 week ago

Question

5.1 Define recruitment and describe the recruitment process.

Answered: 1 week ago