Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

#include #include #include #include qutyio.h / * * Tutorial 0 6 INTRODUCTION: In this week's tutorial you will implement a pseudorandom number generator. This

#include
#include
#include
#include "qutyio.h"
/** Tutorial 06
INTRODUCTION:
In this week's tutorial you will implement a pseudorandom number
generator. This will be of particular relevance to Assessment 2.
*/
/** EX: 6.0
TASK: Define a global unsigned 32-bit integer called "state".
Initialise "state" with a value equal to your student number, where each
decimal digit in your student number represents a hexadecimal literal.
EXAMPLE: If your student number was n12345678 then you should assign the
value 0x12345678 to "state".
Once you have defined this variable uncomment the first printf()
statement in the main() function.
*/
/** CODE: Write your code for Ex 6.0 above this line. */
/** EX: 6.1
TASK: Write the function prototype for a function called "next"
which takes no parameters and returns no result.
*/
/** CODE: Write your code for Ex 6.1 above this line. */
/** EX: 6.2
TASK: Write a function called "print_rand" which returns no result
and takes, as a single argument, a pointer to an unsigned 32-bit
integer.
The function should inspect the least significant two bits of the
integer pointed to by the argument, and depending on the value of the
bits, execute one of the following function calls:
0b00(0): putchar('1');
0b01(1): putchar('2');
0b10(2): putchar('3');
0b11(3): putchar('4');
Once you have written this function uncomment the second printf()
statement in the main() function.
*/
/** CODE: Write your code for Ex 6.2 above this line. */
/** EX: 6.3
TASK: Complete the implementation for the next() function.
next() should:
1. Right shift the bits in "state" by 1 position.
2. If the bit shifted out of state in step 1 was set (1), take the XOR
of "state" with 0xA8E831E0 and store the result in "state".
Once you have written this function uncomment the third printf()
statement in the main() function.
*/
void next(void)
{
/** CODE: Write your code for Ex 6.3 within this function. */
}
int main(void)
{
serial_init();
/** TODO: Uncomment the line below after Ex 6.0 is completed. */
// printf("Ex 6.0: state =0x%08lX
", state);
/** TODO: Uncomment the line below after Ex 6.2 is completed. */
// uint32_t test =0b1100; printf("Ex 6.2: output ="); print_rand(&test); test >>=1; print_rand(&test); test >>=1; print_rand(&test); test >>=1; print_rand(&test); printf("
");
/** TODO: Uncomment the line below after Ex 6.3 is completed. */
// next(); printf("Ex 6.3: state =0x%08lX", state); next(); next(); next(); next(); printf(", state =0x%08lX
", state);
/** EX: 6.4
The variable "state" together with the next() function implement a
linear-feedback shift register, which produces a pseudorandom number
sequence.
This sequence was seeded (initialised) with your student number.
TASK: Write code below to print the next 32 digits derived from this
pseudorandom number sequence using next() and print_rand().
All digits should be printed on a single line without spaces.
NOTE: Call next() to advance "state" prior to printing the first
digit.
TIP: Recall that the unary operator "&" can be used to get a
reference (pointer) to some data.
*/
printf("Ex 6.4: ");
/** CODE: Write your code for Ex 6.4 below this line. */
/** CODE: Write your code for Ex 6.4 above this line. */
printf("
");
// END OF TUTORIAL06 EXERCISES //
// DO NOT EDIT BELOW THIS LINE //
while (1)
; // Loop indefinitely
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions

Question

What is management growth? What are its factors

Answered: 1 week ago