- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
'im frist!'
Admin
1 != 4
Comment rejected.
Admin
The real wtf is still php
Admin
Absolutely! This same algorithm written in Python would have been flawless.
Admin
Oh my God, how did I not think of this approach before. For example, if you need to perform a certain action N times, the solution would be to get a random number K between N-X and N+X and repeat the action K times. Over the life of the software, it'll average out to N!!
Admin
Maybe this developer also used the rand() implementation from https://xkcd.com/221/ , in which case this script will exit every time.
Admin
I guess we may even solve the P-NP problem by lavishly sprinkling extits all over the code – at least, statistically.
Admin
Or perhaps the programmer started their career in Dilbert's accounting department https://dilbert.com/strip/2001-10-25
Admin
Anything written in Python would be flawless
Kek
Admin
I'm almost afraid to ask what the purpose of setting a value in $_GET is meant to do.
Admin
Are we still allowed to say Kek with the Activision Blizzard scandal happening?
Admin
https://www.php.net/manual/en/function.srand.php#117966
If your webserver is using a forked model (e.g. Apache pre-fork model with mod_php), and the random number generator was already seeded, you do get the same random number out of all of them.
rand() in PHP is just as bad as you can imagine.
Admin
I don't see how using git would have made the situation any better.
Admin
You'd get a helpful commit message like "fixed it" with the person who is to blame and a date and time attached. So, minimally better. You could then search the email archive or the bugtracker by date (though I'm betting email only in this case) for the problem description and kind of archeologically work backwards to find out what's going on.
Admin
The only possible way to run a local script using cron is to invoke it through a web server with wget, everybody knows that.
Admin
Are you telling me that seeding the random number generator seeds the random number generator?
Admin
I kind of like it; it has some interesting use-cases. It could be used in a situation where an inspection or action needs to happen regularly, but what's being inspected or acted upon adapts to a pattern of inspection/action. To do the inspection all the time is too costly, but to do it randomly tends to enforce compliance in the meantime.
Admin
Code comments are why you are doing something.
Admin
And here we enter the realm of Bayesian Priors.
Knowing nothing about the quality of PHP as a language, and knowing nothing about the quality of PHP programmers, and knowing nothing about the community of programmers whose chosen language is PHP, or perhaps programmers who have learned PHP as their first language and (presumably with a laugh and a song) happily transferred to, say BrainF*ck, we can definitely assert that it is equally likely that any given programmer is likely to write this self-same garbage either in PHP or in Python or in (language of choice).
Unfortunately, the priors are that (a) this nitwit is a PHP programmer (b) this nitwit is statistically certain to have learned programming via PHP and (c) this nitwit is programming PHP in a way that his employer find eminently cromulent, given the choice of PHP programmers out there.
Given the priors, I would hypothesise that PHP (the language) is indeed a very, very, large part of the problem.
Admin
So it's run on request or on a cron?
Admin
Sounds more like a solution to the halting problem.
Admin
I hate to defend PHP, but...
That comment isn't talking about a web server that forks, it's talking about manually forking within the script using pcntl_fork - in which case it's entirely expected that the RNG state, along with everything else, would be copied to the child. I don't know why they claim it isn't possible to manually reseed in the child - perhaps there was a bug at the time the comment was written that would cause that, or maybe they just screwed up, but it worked fine when I tested it.
Admin
Not true. But maybe you are being sarcastic.