I want to create a program which only needs one random number, so I try to use the address of argc in main function as random source because I think the location of the program in memory is random, and also it can save some include statements, so I tried:
#include <stdio.h>
int main(int argc,const char* argv[]){
printf("%lu\n",(unsigned long int)&argv/sizeof(unsigned long int));
return 0;
}
but I found the output at each time is not very "random": they are multiples of 4:
17591828907268
17591841542404
17591845040388
17591834556676
What is the reason? And is using address of argc as random number possible?
Then I try remove some bits of the address:
#include <stdio.h>
int main(int argc,const char* argv[]){
printf("%lu\n",(unsigned long int)&argv >> 12);
return 0;
}
it looks quite random this time, at least it has both odd and even numbers:
34359070631
34359034616
34359078055
34359080624
is that "correct" way to turn the address of argc into random number?