r/shittyprogramming • u/Smellypuce2 • Jul 31 '18
Shitty RNG
int random_number()
{
int result;
return result;
}Found in my own codebase and it gave me a good chuckle. It was never used and I can't remember what I was originally going to write. I stopped before actually writing the function out and this is what was left.
98
Upvotes
33
u/quez_real Jul 31 '18
I can't make it working, getting 0 all the time, though it could return a pretty random shit, couldn't it?
9
u/[deleted] Jul 31 '18
8
u/duckythescientist Aug 01 '18
Another option is
return (int)&result;which will work somewhat well because of ASLR.I've actually used that to seed a PRNG, but my goal was to be obscure.
3
u/ekolis Aug 08 '18
Result of zero was chosen by random dice roll
3
u/HugoNikanor Sep 02 '18
But it does seem to work rather well!
1
u/detail9453 Aug 02 '18
why can not run this code.
help.
1
u/javaCoder710 Aug 14 '18
Ok well in a way it's returning a random pointer to a slot of memory, which just so happens to be nil :)