this post was submitted on 24 Nov 2025
357 points (99.2% liked)

Programmer Humor

27490 readers
1557 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
[–] kionay@lemmy.world 41 points 1 day ago* (last edited 1 day ago) (2 children)

console.time() jots down the current time, if you do that twice and put stuff in the middle you get two times and the difference between them is how long that stuff took to do

console.timeEnd() uses the last execution of console.time() as the starting point to work out how long the stuff took to do

const originalUUID = crypto.randomUUID() generates a Universally Unique IDentifier, which can be thought of as a very large very random number, by use of a pseudorandom number generator

while(stuff) evaluates the stuff for truthiness (1 + 2 = 5 would be false, 50 < 200 would be true, 'my username starts with the letter k' would be true) it's typically followed by a 'block' of code, that is lines beginning with { and ending with }, but we don't see that here, which means we can read while(stuff) as "keep checking if stuff is true in an endless loop, and only continue to the next line if one of the checks ends up being false"

the stuff here is creating another random UUID, and checking to see if it's the same random number as the first one generated.

functions like this are so incredibly random that chancing upon two executions creating the same number should be practically impossible. staggeringly impossible. If so this code should never complete, as that while check would be endless, never finding a match

the image suggests that one such match was found in about 19 million milliseconds (a bit over 5 hours). this is probably faked, because the absurd unlikelihood of the same number being generated in so much as a single human lifetime, let alone a day, is laughable

the imagine is faked or something is terribly wrong with their pseudorandom number generator

[–] nailbar@sopuli.xyz 5 points 20 hours ago (1 children)

But you can't say that it's fake or broken just because it's unprobable, unless there's supposed to be some additional safe guards to prevent the same random value from repeating within a certain distance from itself.

[–] kionay@lemmy.world 4 points 15 hours ago* (last edited 15 hours ago) (1 children)

from a purely mathematical standpoint, yes

from a practical engineering standpoint, no, it's impossible

I'm pedantic as they come, but pedantry has little use in an engineering discipline, software engineering included

like, if I take a cup of water and pour it into the Pacific Ocean strictly speaking I can say I "single-handed raised the water level of the ocean" and you'd be correct in the most unhelpful way

for the code in question if the PRNG is working as expected then for all meaningful purposes it can be considered impossible

edit oh also to fight pedantry with pedantry, technically even a check that would prevent duplicates might not prevent duplicates because you could argue there's a non-zero chance a random cosmic ray flips just the right bit at just the right moment rendering even that pure chance. anything engineered (and not pure mathematical theory) has to draw the line of plausibility somewhere because we're engineering inside of a chaotic reality. drawing the line to say that the image above is functionally impossible is just fine.

[–] GreyCat@lemmy.world 2 points 9 hours ago

We M-x butterflying now

[–] JetpackJackson@feddit.org 2 points 18 hours ago

Oh wow thank you