>I am, however, going to reiterate my question
My answer probably wasn't clear enough. In general, if you need to know, your design is probably flawed. Since this appears to be an assignment, none of the exceptions apply to you and your design is definitely flawed.
>I'm using the srand((unsigned) &t) statement for a time_t time variable
If t is the time_t variable then you're use its address as the argument to srand, not its value. The cast is unsafe anyway because pointers aren't guaranteed to be representable by an unsigned int. Consider this:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
time_t now;
int i;
now = time(NULL);
if (now == (time_t)-1) {
fprintf(stderr, "Cannot calculate a random seed\n");
return EXIT_FAILURE;
}
srand((unsigned int)now);
for (i = 0; i < 10; i++)
printf("%d ", (int)((double)rand() / RAND_MAX * 100));
printf("\n");
return EXIT_SUCCESS;
}
But it's still not perfect because time_t isn't guaranteed to be representable by unsigned int either. time_t is a restricted arithmetic type, and you can only assume that comparison with (time_t)-1 will work. As such, a more thorough approach is needed for robust code:
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* Hash the bytes of a time_t value */
unsigned int rand_seed(time_t t)
{
unsigned char *p = (unsigned char *)&t;
unsigned seed = 0;
size_t i;
for (i = 0; i < sizeof t; i++)
seed = seed * (UCHAR_MAX + 2U) + p[i];
return seed;
}
int main(void)
{
time_t now;
int i;
now = time(NULL);
if (now == (time_t)-1) {
fprintf(stderr, "Cannot calculate a random seed\n");
return EXIT_FAILURE;
}
srand(rand_seed(now));
for (i = 0; i < 10; i++)
printf("%d ", (int)((double)rand() / RAND_MAX * 100));
printf("\n");
return EXIT_SUCCESS;
}
Of course, the first program will almost always work, it just doesn't have to according to the language definition. Anyway, your problem was that t's virtual address is always the same, so the seed passed to srand never changes.