Integer40* loadHwConfigVariable(int seed); Returns: A pointer to an Integer40 ar
ID: 3857367 • Letter: I
Question
Integer40* loadHwConfigVariable(int seed);
Returns: A pointer to an Integer40 array of 40 random digits. If the input variable seed is set, the random number generator will be seeded, otherwise not. Regardless, the 40 digits will be initialized in 10 unique groups of 4 random digits. Returns NULL if there is an error during creation or initialization of the hwCongVariable.
If the seed passed through is 0 it should generate the same sequence of numbers in every run. It should have a repeating pattern of 5 "random" digits - 10 times.
If the seed thats passed through is 1 it shoud generate a different sequence of numbers in every run. it should contain 40 random digits.
Integer40 is defined as follows and may not be changed.
typedef struct Integer40 {
// a dynamically allocated array to hold a 40
// digit integer, stored in reverse order
int *digits;
} Integer40;
Please Help! The following should be in c code.
Explanation / Answer
#include<stdio.h>
#include <time.h>
#include <stdlib.h>
typedef struct Integer40 {
// a dynamically allocated array to hold a 40
// digit integer, stored in reverse order
int *digits;
} Integer40;
Integer40* loadHwConfigVariable(int seed) {
Integer40* integer40;
int digits[4], i;
if (seed)
srand(time(NULL));
for (i = 0; i < 4; i++)
digits[i] = rand() % 10;
integer40 = malloc(sizeof(Integer40));
integer40->digits = malloc(sizeof(int) * 40);
for (i = 0; i<40; i++) {
integer40->digits[i] = digits[rand()%4];
//printf("%d",integer40->digits[i]); //DEBUG
}
}
int main() {
loadHwConfigVariable(0);
loadHwConfigVariable(1);
return 0;
}
I hope this was what you needed.. Let me know if you like the code. And if you dont like the code, please let me know, i shall try my best to resolve all your issues.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.