this post was submitted on 08 Dec 2023
619 points (96.4% liked)

Programmer Humor

31800 readers
271 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 17 points 8 months ago (3 children)

Loads of beginners in this thread. Here's how it's done in the industry.

The code:

return a;

The test:

a = rand()%100+1;

It works, boss.

[–] [email protected] 4 points 8 months ago* (last edited 8 months ago) (2 children)

This must be a custom random function, because it's standard for random to return a float between 0-1 exclusive. Maybe you meant to multiply by 100 instead of modulo.

[–] [email protected] 10 points 8 months ago (1 children)
[–] [email protected] 5 points 8 months ago

You guys are talking about two different things. Random integer vs random float