this post was submitted on 09 Feb 2024
878 points (100.0% liked)

Programmer Humor

22749 readers
761 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 23 points 1 year ago (3 children)

But rand() is a number between 0-1, so it will never be >10

Basically this is just #define True = False

[–] [email protected] 109 points 1 year ago* (last edited 1 year ago)

The C standard library function int rand(void) returns a pseudo random integer between 0 and RAND_MAX (which should be at least 2^15, depending on the actual implementation).

Depending on the distribution of the pseudo random numbers, it will be true for over > 99% of its applications.

Source: trust me bro, and C++ reference

Furthermore, there is no integer between 0 and 1, but I guess you mean a real number between 0 and 1.

[–] [email protected] 20 points 1 year ago

You're correct in a lot of languages; Excel comes to mind. Just that's not how int rand() works in C.

Sorry, I don't why you're getting snark and even being accused of using the word "integer".

[–] [email protected] 17 points 1 year ago (1 children)

I'm not sure what's worse. The engineer that thought this would work or the company that doesn't do code reviews.

[–] [email protected] 30 points 1 year ago* (last edited 1 year ago) (1 children)

Put it in a package they depend on - nobody reviews those

[–] [email protected] 18 points 1 year ago

Pick a library you already use with many sub-dependencies. Make a new library with your evil code. Name it in line with the step 1 library. Oh hi there "Framework.Microsoft.Extensions.DB.Net.Compatibility" you couldn't possibly have anything bad going on in you, plus you sound really boring to review, I'm sure it's fine.