Linear Congruential Generator - C Program Generates A Random Number And Uses An Algorithm To Generate 9 Other Numbers.
Solution For C Program:/* This C program generates a random number and uses an algorithm to generate 9 other numbers.
* This algorithm is called the linear congruential generator
*/
#include <msp430.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
/*
* main.c
*/
int main(void) {
unsigned int LCG[10];
int i; //counts the position in the array
int a = 97; //coefficient for number generated previously. Defined in lab manual
int b = 1; //defined in lab manual
int m = 1023; //modulo 1023 to generate a number between 1 and 1024
srand((time(NULL))); //seeds computer time for rand()
LCG[0] = rand()%1023; //first number in array is a randomly generated number modulo 1023
//for loop generates 9 subsequent numbers from first number and stores them in an array in the order that they are generated
for(i=1; i<10;++i){
LCG[i]=(a*LCG[i-1] + b)%m;
}
}