I am trying to generate a random number using all the bits of an int. when I use the rand() fuction, it never seems to use the first bit, so I tried to shift the whole thing one place. However, when I try to print the new shifted number it always prints 4294967295, so I guess that's an overflow. Why can't I use that bit, though? is there a way?
If the first bit is not used it works fine, like this (print is before and after the shift of the random number):
00000100001100111111001010010111
00001000011001111110010100101110
but if the first bit is needed, this happens:
01010110100001110011110011011111
42949672950101101000011100111100110111110
please help!! It's technically working, it just prints the number first...
typedef struct{
int blocks[NUM_BLOCKS];
} WWord;
void printbits(unsigned int n){
int i;
//printf("%u = ",n);
for(i=SIZE_OF_INT*SIZE_OF_BYTE-1;i>=0;i--){
int mask = 1<<i;
int maskedn = n&mask;
int thebit = maskedn >> i;
printf("%u",thebit);
}
printf("\n");
}
void fillword(WWord *word){
int i;
for(i=0; i<NUM_BLOCKS;i++){
unsigned int ran = rand();
printbits(ran);
ran = ran<<1;
printbits(ran);
word->blocks[i] = ran;
//word->blocks[i]<<1;
printf("\n");
}
}