R
Ray D.
Okay, so I'm trying to typecast a random integer into a double, and
store that in an array of doubles. Here is my code:
void randomMatrix(double *x) {
int i, random;
// Generate pseudo-random sequence
// Restrict range to 9
for(i = 0; i < SIZE; i++){
random = rand()%9;
printf("random is %i, ", random);
x = (double)random;
printf("%i\n", x);
}
}
I call this function twice, and here is the output for each time (Note
that SIZE = 6 in the loop above)
random is 8, 1075838976
random is 7, 1075576832
random is 6, 1075314688
random is 1, 1072693248
random is 1, 1072693248
random is 2, 1073741824
random is 6, 1075314688
random is 3, 1074266112
random is 3, 1074266112
random is 0, 0
random is 4, 1074790400
random is 5, 1075052544
As you can see, I first print out the integer returned from the rand()
function, then I attempt to typecast to a double and print this, but
it's pretty clear they do not match, any idea what is going on?? I
appreciate any help you may have! Thanks.
store that in an array of doubles. Here is my code:
void randomMatrix(double *x) {
int i, random;
// Generate pseudo-random sequence
// Restrict range to 9
for(i = 0; i < SIZE; i++){
random = rand()%9;
printf("random is %i, ", random);
x = (double)random;
printf("%i\n", x);
}
}
I call this function twice, and here is the output for each time (Note
that SIZE = 6 in the loop above)
random is 8, 1075838976
random is 7, 1075576832
random is 6, 1075314688
random is 1, 1072693248
random is 1, 1072693248
random is 2, 1073741824
random is 6, 1075314688
random is 3, 1074266112
random is 3, 1074266112
random is 0, 0
random is 4, 1074790400
random is 5, 1075052544
As you can see, I first print out the integer returned from the rand()
function, then I attempt to typecast to a double and print this, but
it's pretty clear they do not match, any idea what is going on?? I
appreciate any help you may have! Thanks.