首页 > > 详细

COMP9024 21T3 Randomised Algorithms

 COMP9024 21T3 Randomised Algorithms

Congratulations on reaching the end of this course!
Please note:
Just 1 program to submit.
Note the early submission deadline: Friday, 19 November, at 5:00:00pm.
 
 
 
1.(Random numbers)
a.A program that simulates the tosses of a coin is as follows:
b.#define NTOSSES 20
c.srand(time(NULL));
d.int i, count = 0;
e.for (i=0; i
f.   int toss = rand() % 2;     // toss = 0 or 1
g.   if (toss == 0) {
h.      putchar('H');
i.      count++;
j.   } else {
k.      putchar('T');
l.   }
m.}
n.printf("\n%d heads, %d tails\n", count, NTOSSES-count);
Sample output is:
HHTTTTHHTTTHHTHHHHHH
12 heads, 8 tails
1.What would an analogous program to simulate the repeated rolling of a die look like?
2.What could be a sample output of this program?
o.If you were given a string, say "hippopotamus", and you had to select a random letter, how would you do this?
p.If you have to pick a random number between 2 numbers, say i and j (inclusive), how would you do this? (Assume i
q.Write a C program that generates a random password consisting of any letter, number or symbol between Ascii 33 (= '!') and 126 (= '~'). When executed, the first command-line argument is the seed used by the random number generator, i.e. by rand(), and the second argument is the length of the password.
An example of the program executing could be
./mypassword 1 8
v%b82j1S
which seeds the random-number generator with 1 and generates a password of length 8.
We have created a script that can automatically test your program. To run this test you can execute the dryrun program that corresponds to this exercise. It expects to find a file named mypassword.c in the current directory.
You can use dryrun as follows:
9024 dryrun mypassword
Note: It is important in this exercise that you use the random number generator as specified in the lecture (and generalised in Exercise 1.c above), otherwise the outputs will not match. If you use a different method to generate random numbers, the testcases will 'fail', but your program could still be perfectly correct. The output may also be different on your own computer.
Hint: You may assume that the maximum password length is 32.
 
 
Assessment
Submit your solution to Exercise 1d using the following give command:
give cs9024 week10 mypassword.c
Make sure you spell the filenames correctly. You can run give multiple times. Only your last submission will be marked.
The deadline for submission is Friday, 19 November 5:00:00pm.
The program is worth 2 marks. Auto-marking will be run by the lecturer several days after the submission deadline using different test cases than dryrun does.
Hints:
Programs will not be manually marked.
It is important that the output of your program follows exactly the format shown above, otherwise auto-marking will result in 0 marks.
Ensure that your program compiles on a CSE machine with the standard options -Wall -Werror -std=c11. Programs that do not compile will receive 0 marks.
dryrun and auto-marking also check the correct usage of dynamic memory allocation and pointers as well as the absence of memory leaks.
Do your own testing in addition to running dryrun.
 
 
Plagiarism
Group submissions will not be allowed. Your programs must be entirely your own work. Plagiarism detection software will be used to compare all submissions pairwise (including submissions for similar assessments in previous years, if applicable) and serious penalties will be applied, including an entry on UNSW's plagiarism register.
Do not copy ideas or code from others
Do not use a publicly accessible repository or allow anyone to see your code
Please refer to the on-line sources to help you understand what plagiarism is and how it is dealt with at UNSW:
Plagiarism and Academic Integrity
UNSW Plagiarism Policy Statement
UNSW Plagiarism Procedure
Reproducing, publishing, posting, distributing or translating this page is an infringement of copyright and will be referred to UNSW Conduct and Integrity for action.
联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!