r/C_Programming • u/usoleta • Aug 30 '26
Etc random number hack
#include <stdio.h>
int main() {
int s[90];
printf("%d\n",s[43]);
}
0
Upvotes
r/C_Programming • u/usoleta • Aug 30 '26
#include <stdio.h>
int main() {
int s[90];
printf("%d\n",s[43]);
}
13
u/ImTheRealCryten Aug 30 '26
If you’re insinuating that the stack is a good place to source random data, I think you should rethink that idea.
7
u/This_Growth2898 Aug 30 '26
xkcd had more sane proposition for a random number
9
u/jirbu Aug 30 '26
Nowhere near random. Every time you run the program you'll get the same result (on a standard and sane OS). You should have used 42, though.
3
u/Due_Sentence_2660 Aug 30 '26
I mean, not completely "random" as much as "garbage value" lol, which means this doesn't even assign an equal probability to every number.
2
u/Glittering-Work2190 Aug 30 '26
0 has a higher chance than any other number.
2
u/Zirias_FreeBSD Aug 30 '26
there are two ways to think about that ...
0.1
u/MrLongbottom5 Aug 30 '26
Thats just garbage data it would be 0 mostly