If you want to generate random number alike throwing a dice

If you want to generate random number alike throwing a dice. Which sentence of this program should be modified? What will be the value of new sentence?

#include <stdint.h> // preprocessor directive to include file

uint8_t random(void); // function declaration

uint32_t M = 1; // global variable

int main(void) {   // main function

       uint8_t x;

       x = random(); // function call

       return 0;

}

uint8_t random(){ // function defination

       uint8_t result;

       M = 1664525*M + 1013904223;

       result = 1 + ((uint8_t) M % 256);

       return result;

}

Solution

int main(void) {   // main function

       uint8_t x;

       x = random();

       return 0;

}

uint8_t random(){ // function defination

       uint8_t result;

       M = 1664525*M + 1013904223;

       result = 1 + ((uint8_t) M % 6);//modified sentence.. %5 will generate remainders 0,1,2,3,4,5 adding them 1, will //make 1,2,3,4,5,6... which is outcome of dice

       return result;

}

If you want to generate random number alike throwing a dice. Which sentence of this program should be modified? What will be the value of new sentence? #include

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site