Question: ROLL THAT DICE......RANDOMLY This assignment is to be attempted on an individual basis. If your code is unique and does something a bit random looking
ROLL THAT DICE......RANDOMLY
This assignment is to be attempted on an individual basis. If your code is unique and does
something a bit random looking with the DICE...you will pass the assignment. If two people
submit exactly the same code....thats a problem. What are the chances of that! (Obviously
the basic example code I will supply is not enough to just give me back). The max value for
this assignment is 15%. (Very generous!). But I will on the lookout for plagiarism.
So the best solution for this problem is to have some fun doing it yourself!
The problem:
I want you to develop a program that rolls a dice and gives a random result. I will leave the
specific approach to yourself. However, I would suggest that the start of the DICE ROLL is
done by using a switch at PORT A.
When and how the rolling stops I will leave to you to decide.
What you should remember is that the process in the simulator may appear a bit slow, but
would appear much faster in a real system.....and we may get to look at that. So dont worry
if the process appears a bit slow.
The appearance of a DICE ROLLING (changing) is not essential....but looks good if you could
incorporate into your program and will earn credit. Look at the example programs. The
DICE_DEMO_1 file simply changes from 1 6 -1 -and keeps repeating. That is NOT random.
The more important aspect of this program is to ensure that when the DICE stops rolling,
the number that is displayed appears as random as possible.
To help with this there is a nice little program in the book that generates pseudo random
sequences. There is an error in the book code. But I have uploaded the correct code to
Bright Space. This is example 3.5 in KATZEN and I have referred to it in lab class. I include
the section below for you convenience. (Note the code error is
MOVWF TEMP,F
).
A few points to note......if you run the PRBS_1 program with the DICE connected, in a
simplistic manner as in the example I supplied, you will NOT output a very random number.
This is because only a limited number of the generated codes will change the DICE. Run and
step thro this program and you will see what I mean. Also, it starts...(seeded) by the same
value 1 every time it is run. This is more or less the code form the book but just includes a
few modifications such as calling the code as a subroutine.
The seeding (initial value) does not have to be 1....
but cannot be zero
. Now thats a hint at
how you could increase randomness? Note the following comment from Wiki
A pseudorandom number generator's number sequence is completely determined by the
seed: thus, if a pseudorandom number generator is reinitialized with the same seed, it will
produce the same sequence of numbers
.
The choice of a good random seed is crucial in the field of
computer security
. When a
secret
encryption
key
is
pseudorandomly
generated
, having the seed will allow one to
obtain the key. High
entropy
is important for selecting good random seed data.
[1]
........
Random seeds are often generated from the state of the computer system (such as
the
time
),
I suggest you look at something, maybe on YouTube, about the idea of PRBS to give you the
flavour of what you are doing. For those amongst you who pursue computer or
communications engineering you are likely to use PRBS concepts again. In fact the random
number codes generated can be useful for generating random tables of data for some of our
exercises. The concept is often used in relation to testing systems. You may even figure out
a more sophisticated approach to generating random sequences.
I am leaving it open to you to design a solution using some imagination. However, the
submitted assignment must comply with the following guidelines.
1.
A short written description of the technique you are using in the program, about a
paragraph.
2.
A flowchart outlining the key steps involved. The low-level details in subroutines do
not need to be described in the chart, but the subroutine calls should be clearly
referred to.
3.
The program should be modular i.e. be written in definite sections using using
subroutines. Or to put it another way...have a good structure.
4.
The code should be commented.
5.
Also include 3 screen shots of the simulator in step mode executing key segments of
your program and state what the action is.
6.
As with the other lab assignments all of the above should be inserted into a Word
Doc for submission
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
