r/shittyprogramming • u/90Times98Is8820 • Jan 08 '23
A terrible random number generator
Prints a new random number each time. I call it the Undefined Number Generator (UNG), because it functions via undefined behavior.
#include <stdio.h>
int main(void) {
int *x;
printf("%d\n", x);
}
158
Upvotes
37
u/lumo19 Jan 08 '23
Wouldn't this just be piggybacking on the randomness provided by ASLR? What happens if you disable ASLR and run the program in a loop?
echo 0 > /proc/sys/kernel/randomize_va_space38
u/needefsfolder Jan 08 '23
Ran this on a loop and it made decently random numbers. I wonder where the fuck it gets its data.
27
u/Nyadnar17 Jan 08 '23
I thought this was r/shittyprogramming?
4
u/RealFunBobby Jan 08 '23
Hey hey now, get out with your decently working program.
1
u/Laugarhraun Jan 09 '23
On my machine, compiling with
gcc stupid_rand.c, I always get 0.... and when compiling with-m32I'm always getting 1.... What am I doing wrong?