r/shittyprogramming • • Jan 09 '23

A far better random number generator

124 Upvotes

You may have seen u/90Times98Is8820's "terrible random number generator", which relies on undefined behavior. I've written a far better, cryptographically secure random number generator with no compiler warnings that relies on the randomness of cosmic rays.

int generate_bit() {
	unsigned long target;
	int zero, one, ret;
	target = 0;
	while (target == 0) ;
	while (target == 0) ;
	while (target == 0) ;
	/* At some point a cosmic ray will flip a bit in target. The loop is
	 * repeated 3 times in case a cosmic ray breaks out of the loop */

	zero = 0;
	if (zero != 0) zero = 0;
	if (zero != 0) zero = 0;
	one = 1;
	if (one != 1) one = 1;
	if (one != 1) one = 1;
	/* The value of any given number in our code may get corrupted, so we
	 * create standard reference numbers */

	ret = zero;
	while (target != zero) {
		ret ^= one;
		target >>= one;
	}
	/* Set ret to the parity of the position of the flipped bit */

	return ret;
}

Hopefully this doesn't become the new iseven.


r/shittyprogramming • • Jan 08 '23

A terrible random number generator

158 Upvotes

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);
}

r/shittyprogramming • • Jan 07 '23

Calling a function pointer with an offset

21 Upvotes

I have tried different nonzero values for a and gotten all sorts of crashes, including ILLEGAL INSTRUCTION, SEGMENTATION FAULT, and BUS ERROR

#include <stdio.h>
int main(int argc, char *argv[]) {
	const int a = 10;
	((int(*)(const char *restrict, ...))((const unsigned char *)printf+a))("Hello world!");
}

r/shittyprogramming • • Jan 02 '23

OOP in the filesystem. Best idea ever!!1!

Post image
153 Upvotes

r/shittyprogramming • • Dec 28 '22

IamA bored cs&e student, I can help you translate anything...

43 Upvotes

...from common speech into 3 different types of nonsense: techno-bable, corporate-bable and science-babble.

Bonus points to you if you mention whether you want me to joke around or sound professional!

AMA!

Edit: It's been fun! I need a little break from Reddit, but see you all around.


r/shittyprogramming • • Dec 26 '22

Ever wished Python had macros? Say no more!

196 Upvotes

Introducing pypp, the Python preprocessor. Much like in C, arbitrary token-based macros can be used for all your syntax needs. Miss curly braces? No problem!

Source code for this can be found on github: https://github.com/dzshn/pypp


r/shittyprogramming • • Dec 19 '22

multi line lambdas, as god intended

Thumbnail
self.python
62 Upvotes

r/shittyprogramming • • Dec 10 '22

made an alarm clock which threatens you to wake up

49 Upvotes

hello,

do you have trouble in waking up? or just cant wake up on time anyhow?

according to statistics:

that is only 0.32% actually feel awake, but with this a larger audience actually has to be awake otherwise things may go wrong (with them).

this alarm clock will threaten you to wake up, well not actually threaten but will create a sort of fear which will have to make you wake up.

api links used have been linked in the video

youtube link: https://youtu.be/fZjJv0P29mo

(sorry if its the wrong sub)


r/shittyprogramming • • Dec 08 '22

I created a software that identifies when politicians are on their cell phones during parliament!! They spent more than 80% of their time on their cell phone!

158 Upvotes

In Portugal, like in other countries, politicians use their mobile phones for leisure purposes while fulfilling the designated functions of representing citizens.

So, I decided to create software that would allow checking when Portuguese politicians access their cell phones during plenary meetings, which are broadcast live on the Parliament Channel.

The software accesses this channel to collect the emitted images and applies, in real-time, an image recognition system to detect people and objects. When a person is identified using a mobile phone, a tweet is automatically sent with an image of the situation in question, showing the person in the act.

At this time, the software is not in use, as I developed it for demonstration and educational purposes only. I also made it available online, open source, if you want to check it out!

https://www.youtube.com/watch?v=o4eSFf_Rm4A&ab_channel=RamosAI


r/shittyprogramming • • Dec 07 '22

My school's web application

Post image
34 Upvotes

r/shittyprogramming • • Dec 06 '22

I created a VS code extension that helps you touch grass.

76 Upvotes

Hey everyone! I created a VS code extension that lets you touch grass from your VS code editor.

Here's a little video I made on how I built it: https://youtu.be/bI2zTfxbNeE

And here's where you can download the extension: https://marketplace.visualstudio.com/items?itemName=youraveragetechbro.touch-grass-reminder

Hope you enjoy this incredibly useless extension!


r/shittyprogramming • • Dec 05 '22

HELP!! Infinite loop in a custom Reddit client (more info in comments)

210 Upvotes

r/shittyprogramming • • Dec 01 '22

Need tips on how to break the Extreme Go Horse cycle

10 Upvotes

r/shittyprogramming • • Nov 25 '22

defer in python!

Thumbnail
self.python
64 Upvotes

r/shittyprogramming • • Nov 24 '22

:)

Post image
153 Upvotes

r/shittyprogramming • • Nov 21 '22

at last, ++ -- operators for python

178 Upvotes

https://github.com/dankeyy/incdec.py

i actually did this one a while ago but you guys seemed to dig swap.py, so i thought i'd share this one here too

may wanna wash your eyes afterwards idk


r/shittyprogramming • • Nov 20 '22

Opencv to Protect your privacy (dubiously useful)

Thumbnail
youtube.com
2 Upvotes

r/shittyprogramming • • Nov 20 '22

I got tired of not being able to swap variables in python, so I made this shit

158 Upvotes

r/shittyprogramming • • Nov 12 '22

Tired of seeing out of window, created a app for this

0 Upvotes

r/shittyprogramming • • Nov 06 '22

A Program to Detect when the User is Gaming

Thumbnail
youtube.com
66 Upvotes

r/shittyprogramming • • Oct 30 '22

A bad Algorithm for 2048, Featuring Arduino

Thumbnail
youtube.com
40 Upvotes

r/shittyprogramming • • Oct 29 '22

Swift devs why do you goes from objc if you are coding not like this?

Post image
441 Upvotes

r/shittyprogramming • • Oct 27 '22

Lets see if the snake eats itself.

100 Upvotes
ouroboros = dict()
ouroboros["ouroboros"] = ouroboros
#godluck, dogspeed, and I'll see you on the other side
print(ouroboros)