Comment On Classic WTF: SuperRand

Nearly six years ago, Brian J gave up being a software developer to start a career in law enforcement. He specifically avoided the world of high-tech cyber crime, and wanted to start life anew as your everyday suburban cop. Of course, with a computer engineering degree and several years of IT experience, technology challenges tend to follow him wherever he goes. [expand full text]
« PrevPage 1 | Page 2Next »

Re: Classic WTF: SuperRand

2012-12-26 08:16 • by anon (unregistered)
I wouldn't want to be officer #24...

http://mathworld.wolfram.com/UniformSumDistribution.html

Re: Classic WTF: SuperRand

2012-12-26 08:21 • by ¯\(°_o)/¯ I DUNNO LOL (unregistered)
That's a lot of work to just return 4.

http://xkcd.com/221/

Re: Classic WTF: SuperRand

2012-12-26 08:39 • by Dotan Cohen (unregistered)
397954 in reply to 397952
That is a feature, not a bug. Officer #1 wrote the script.

Re: Classic WTF: SuperRand

2012-12-26 09:22 • by WC (unregistered)
397956 in reply to 397952
anon:
I wouldn't want to be officer #24...

http://mathworld.wolfram.com/UniformSumDistribution.html


On the other hand, Officer #1 gets off scott free, if I'm reading that code correctly. (And I'm not at all sure of that. lol)

Re: Classic WTF: SuperRand

2012-12-26 09:56 • by Gary (unregistered)
Don't you know? It's not a random number unless it has a bell curve distribution.

Re: Classic WTF: SuperRand

2012-12-26 10:53 • by RFmich (unregistered)
I am not a number I am a free man..

Re: Classic WTF: SuperRand

2012-12-26 11:52 • by Ralph (unregistered)
It is delightful the way he explains "adding them together will improve the randomness by" and then stops without his justification. I'd love to know what he was thinking, but perhaps his brain itself went blank at this same point.

Re: Classic WTF: SuperRand

2012-12-26 11:57 • by Tim (unregistered)
Instead of hard coding the total number of officers, it should have been read from an XML file.

Might as well have another XML file for the total divided by two, while we're at it.

Re: Classic WTF: SuperRand

2012-12-26 11:58 • by Henry (unregistered)
Cops don't like speed traps? Neither do we. So why do they exist?

Re: Classic WTF: SuperRand

2012-12-26 12:26 • by Loren Pechtel
397966 in reply to 397965
Henry:
Cops don't like speed traps? Neither do we. So why do they exist?


Because politicians like them.

Re: Classic WTF: SuperRand

2012-12-26 12:27 • by Hacky (unregistered)
397968 in reply to 397965
To get people to slow down and to generate revenue for the department.

Re: Classic WTF: SuperRand

2012-12-26 12:27 • by Rick
397969 in reply to 397965
Henry:
Cops don't like speed traps? Neither do we. So why do they exist?
I am quite happy when police park in front of my home with a radar gun and ticket speeders. I have offered coffee, but I don't think they are allowed to accept.

Re: Classic WTF: SuperRand

2012-12-26 12:28 • by Brendan Kidwell
397970 in reply to 397965
Henry:
Cops don't like speed traps? Neither do we. So why do they exist?

Gotta have some form of deterrence. Also, practically free revenue for the town or local police force.

Re: Classic WTF: SuperRand

2012-12-26 13:09 • by GNU Pepper
Brian ... commented-out the superrand() function.

Commenting out dead code instead of deleting it is TRWTF here.

Re: Classic WTF: SuperRand

2012-12-26 13:20 • by atk (unregistered)
397974 in reply to 397973
GNU Pepper:
Brian ... commented-out the superrand() function.

Commenting out dead code instead of deleting it is TRWTF here.


It is good to.comment out and retain incorrect code in seceral cases. When the code is subtly wrong, keeping it (and adding explanation why it is wrong) shows subsequent maintainers that this path has been tried before, and that it was incorrect, thus avoiding reintroduction of the subtle error. It is also useful when a serious error is introduced, for similar reason. I remeber there being a third good reason, but I fail to recall at the moment.

Re: Classic WTF: SuperRand

2012-12-26 13:23 • by Henry (unregistered)
397975 in reply to 397970
Brendan Kidwell:
Henry:
Cops don't like speed traps? Neither do we. So why do they exist?
Gotta have some form of deterrence.
So the possibility of wrecking my car and myself by going an unsafe speed doesn't count as "deterrence"?

I've evaluated the probability of harm that will come to me as a result of going ___ miles per hour and concluded that it is an acceptable risk. But, the possibility of encountering the cop must be a higher risk, otherwise it would not deter me. This means the cop himself, and the various threats that he represents, are more dangerous than the original "offense" of speeding.
Brendan Kidwell:
practically free revenue for the town or local police force.
Aaah, now you've got it. Legalized highway robbery, plain and simple.

Re: Classic WTF: SuperRand

2012-12-26 13:46 • by foxyshadis (unregistered)
397976 in reply to 397974
atk:
GNU Pepper:
Brian ... commented-out the superrand() function.

Commenting out dead code instead of deleting it is TRWTF here.


It is good to.comment out and retain incorrect code in seceral cases. When the code is subtly wrong, keeping it (and adding explanation why it is wrong) shows subsequent maintainers that this path has been tried before, and that it was incorrect, thus avoiding reintroduction of the subtle error. It is also useful when a serious error is introduced, for similar reason. I remeber there being a third good reason, but I fail to recall at the moment.

Shame.

Re: Classic WTF: SuperRand

2012-12-26 13:48 • by TheLazyHase
397977 in reply to 397975
Henry:

I've evaluated the probability of harm that will come to me as a result of going ___ miles per hour and concluded that it is an acceptable risk.


... and, of course, the fact that part of this risk is imposed not upon you but upon other people is meaningless.

And that come in top of the fact that human being fail utterly at understanding exactly what risk they tolerate.

As have said someone, "if speed ticket were punished with electric chair and drunken driving with public beheading, they would be less death on the road". Which, indeed, tie with the fact that the cop would be more dangerous than the original offence :p

Re: Classic WTF: SuperRand

2012-12-26 13:58 • by the beholder (unregistered)
397978 in reply to 397975
Henry:
Brendan Kidwell:
Henry:
Cops don't like speed traps? Neither do we. So why do they exist?
Gotta have some form of deterrence.
So the possibility of wrecking my car and myself by going an unsafe speed doesn't count as "deterrence"?

I've evaluated the probability of harm that will come to me as a result of going ___ miles per hour and concluded that it is an acceptable risk. But, the possibility of encountering the cop must be a higher risk, otherwise it would not deter me. This means the cop himself, and the various threats that he represents, are more dangerous than the original "offense" of speeding.
Even supposing you have a very good grasp on reality about being a good driver, there's no way I'd believe every other Joe out there thinks himself as good a driver as he actually is. The same holds true about the difference of your car being under adequate conditions, and you thinking it is.

Re: Classic WTF: SuperRand

2012-12-26 14:00 • by the beholder (unregistered)
397979 in reply to 397974
atk:
GNU Pepper:
Commenting out dead code instead of deleting it is TRWTF here.


It is good to comment out and retain incorrect code in seceral cases. When the code is subtly wrong, keeping it (and adding explanation why it is wrong) shows subsequent maintainers that this path has been tried before, and that it was incorrect, thus avoiding reintroduction of the subtle error. It is also useful when a serious error is introduced, for similar reason. I remember there being a third good reason, but I fail to recall at the moment.
To prove its existence when people on TDWTF claim it must be fabricated because "nobody would be so stupid"

Re: Classic WTF: SuperRand

2012-12-26 14:39 • by jrw (unregistered)
397980 in reply to 397975
Henry:
Brendan Kidwell:
Henry:
Cops don't like speed traps? Neither do we. So why do they exist?
Gotta have some form of deterrence.
So the possibility of wrecking my car and myself by going an unsafe speed doesn't count as "deterrence"?

I've evaluated the probability of harm that will come to me as a result of going ___ miles per hour and concluded that it is an acceptable risk. But, the possibility of encountering the cop must be a higher risk, otherwise it would not deter me. This means the cop himself, and the various threats that he represents, are more dangerous than the original "offense" of speeding.


Can't decide: is Henry a narcissist, delusional, or troll? Hmmm....

Re: Classic WTF: SuperRand

2012-12-26 15:04 • by Decius (unregistered)
Why is something like this randomly determined? There should be a deterministic aspect, because the person who did the speed trap yesterday shouldn't have the same independent chance of doing it today and tomorrow.

Re: Classic WTF: SuperRand

2012-12-26 15:31 • by Ken B (unregistered)
I love the test to make sure that, if the "good" random number equals the "bad" random number, another "good" random number is generated.

Re: Classic WTF: SuperRand

2012-12-26 15:33 • by Ken B (unregistered)
397983 in reply to 397975
Henry:
Brendan Kidwell:
Henry:
Cops don't like speed traps? Neither do we. So why do they exist?
Gotta have some form of deterrence.
So the possibility of wrecking my car and myself by going an unsafe speed doesn't count as "deterrence"?

I've evaluated the probability of harm that will come to me as a result of going ___ miles per hour and concluded that it is an acceptable risk. But, the possibility of encountering the cop must be a higher risk, otherwise it would not deter me. This means the cop himself, and the various threats that he represents, are more dangerous than the original "offense" of speeding.
Unfortunately, too many people never consider the fact that speeding increases the risk of harming others.

Re: Classic WTF: SuperRand

2012-12-26 16:09 • by Blakeyrat (unregistered)
Speedin isn't a crime if those other people are tôo scared they should piss off its survival of the fittest either slam with the best or jam with the rest and if you can't step it up on the road the you're a Slomo dead weight and you might as well go kill yourself cuz or only gonna get juiced and jammed

Re: Classic WTF: SuperRand

2012-12-26 16:19 • by BillTheGeek (unregistered)
397985 in reply to 397984
Blakeyrat:
Speedin isn't a crime if those other people are tôo scared they should piss off its survival of the fittest either slam with the best or jam with the rest and if you can't step it up on the road the you're a Slomo dead weight and you might as well go kill yourself cuz or only gonna get juiced and jammed

I don't know about your driving, but your fingers definitely went too fast here and got too far ahead of your brain.

Re: Classic WTF: SuperRand

2012-12-26 16:24 • by Seminymous Coward (unregistered)
397986 in reply to 397983
Ken B:
Unfortunately, too many people never consider the fact that speeding increases the risk of harming others.

Speed limits are not motivated by rational safety concerns. Don't trust your intuition or even my claims; check up on the research in the field for yourself.

Re: Classic WTF: SuperRand

2012-12-26 16:33 • by Meep (unregistered)
397987 in reply to 397974
atk:
GNU Pepper:
Brian ... commented-out the superrand() function.

Commenting out dead code instead of deleting it is TRWTF here.


It is good to.comment out and retain incorrect code in seceral cases. When the code is subtly wrong, keeping it (and adding explanation why it is wrong) shows subsequent maintainers that this path has been tried before, and that it was incorrect, thus avoiding reintroduction of the subtle error. It is also useful when a serious error is introduced, for similar reason. I remeber there being a third good reason, but I fail to recall at the moment.


No one who would try to write their own random function is going to read some commented code. You have to understand the mind of a stupid motherfucker: it is a place utterly devoid of intellectual curiosity.

Re: Classic WTF: SuperRand

2012-12-26 18:07 • by BillTheGeek (unregistered)
397989 in reply to 397987
Meep:
atk:
It is good to.comment out and retain incorrect code in seceral cases. When the code is subtly wrong, keeping it (and adding explanation why it is wrong) shows subsequent maintainers that this path has been tried before, and that it was incorrect, thus avoiding reintroduction of the subtle error. It is also useful when a serious error is introduced, for similar reason. I remeber there being a third good reason, but I fail to recall at the moment.


No one who would try to write their own random function is going to read some commented code. You have to understand the mind of a stupid motherfucker: it is a place utterly devoid of intellectual curiosity.


That is an unfair and inaccurate characterization. The worst random number generator I have personally encountered had a period of six (!) unique numbers, and it was written by a friend of mine who is otherwise a good programmer. Writing a good (pseudo)random number generator requires some specialized knowledge and experience, and I'm sure that many talented programmers (as well as many not-so-talented ones) have screwed up in this area (RANDU, anyone?).

Re: Classic WTF: SuperRand

2012-12-26 18:17 • by spamcourt
397990 in reply to 397984
Blakeyrat:
Speedin isn't a crime if those other people are tôo scared they should piss off its survival of the fittest either slam with the best or jam with the rest and if you can't step it up on the road the you're a Slomo dead weight and you might as well go kill yourself cuz or only gonna get juiced and jammed

"Blakeyrat"? You're not that good at trolling son.

Re: Classic WTF: SuperRand

2012-12-26 18:30 • by Norman Diamond (unregistered)
397991 in reply to 397973
GNU Pepper:
Brian ... commented-out the superrand() function.
Commenting out dead code instead of deleting it is TRWTF here.
Regardless of whether commenting out or deleting, TRWTF is removing the speed up loop when the business user is operating a speed trap.

Re: Classic WTF: SuperRand

2012-12-26 18:33 • by Dan (unregistered)
397992 in reply to 397989
BillTheGeek:
Meep:


No one who would try to write their own random function is going to read some commented code. You have to understand the mind of a stupid motherfucker: it is a place utterly devoid of intellectual curiosity.


That is an unfair and inaccurate characterization. The worst random number generator I have personally encountered had a period of six (!) unique numbers, and it was written by a friend of mine who is otherwise a good programmer. Writing a good (pseudo)random number generator requires some specialized knowledge and experience, and I'm sure that many talented programmers (as well as many not-so-talented ones) have screwed up in this area (RANDU, anyone?).


Writing a good random number generator from scratch is very tricky. However using the one built into your language is not. Knowing these 2 facts is not particularly tricky. A little Googling before you even attempt to build your own would be warranted.

captcha: transverbero: commenting on a comment of a comment

Re: Classic WTF: SuperRand

2012-12-26 18:37 • by Norman Diamond (unregistered)
397993 in reply to 397989
BillTheGeek:
The worst random number generator I have personally encountered had a period of six (!) unique numbers, and it was written by a friend of mine who is otherwise a good programmer.
You can name your friend. After all, he humbly published his mistake in the second volume of The Art of Computer Programming, and decently labelled it "Algorithm K".

(And yes I know that if I wrote an "Algorithm D" it would be worse.)

Re: Classic WTF: SuperRand

2012-12-26 18:56 • by Daniel (unregistered)
397994 in reply to 397975
Henry:
So the possibility of wrecking my car and myself by going an unsafe speed doesn't count as "deterrence"?


For anybody with any sense, yes, it would. For the sort of morons who actually speed clearly it does not as is demonstrated by the fact that they do speed and that a lot of them crash, quite a lot of them into other people. In many cases they are driving a car they just stole and/or they are too drunk to care.

Deterrence is fine for dealing with people who have enough sense to be deterred, either from the outset or maybe after a few tickets if they are a bit slow on the uptake. For the real morons traffic cops are there to get them arrested, off the roads and banned from driving and to get any stolen cars returned to their rightful owners before they get too badly damaged.

Re: Classic WTF: SuperRand

2012-12-26 19:20 • by decet (unregistered)
397995 in reply to 397975
Henry:
Brendan Kidwell:
Henry:
Cops don't like speed traps? Neither do we. So why do they exist?
Gotta have some form of deterrence.
So the possibility of wrecking my car and myself by going an unsafe speed doesn't count as "deterrence"?

I've evaluated the probability of harm that will come to me as a result of going ___ miles per hour and concluded that it is an acceptable risk. But, the possibility of encountering the cop must be a higher risk, otherwise it would not deter me. This means the cop himself, and the various threats that he represents, are more dangerous than the original "offense" of speeding.

Riiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiight.
I'm sure this guy makes a totally rational risk-benefit evaluation of the maximum speed he's gonna go at every time he gets in the car.

Because, you know, humans brains are a collection of parts that work together to pick the most rational choice every time and maximize a single utility function, and not an amalgam of parts so unrelated and poorly glued together that would make any 500-MLOC enterprise software written in MUMPS look like a modular, perfectly structured system. This is why nobody has ever taken a decision that was detrimental in the long term, not even when they're angry, drunk or tired.

And it's not like the parts that actually reason are plagued with cognitive biases of various sorts either. I mean, surely 80% of the people won't think they are in the top 50% of drivers.

You can tell humans are very rational because, when given the choice between object A (cheaper) and object B (better but more expensive), their preferences won't seem to magically switch to B when you put both options next to C (more expensive than B but worse), because they will definitely pay 100 times more to save 200000 birds than to save 2000, because they won't answer different things when you ask them to estimate "8 x 7 x 6 x 5 x 4 x 3 x 2 x 1" vs "1 x 2 x 3 x 4 x 5 x 6 x 7 x 8", and because prisoners are not 7 times more likely to get paroled if they appear before the judges in the early morning instead of late in the afternoon.

That's why Wikipedia does not have a long-ass list of cognitive biases showing that people get basically everything wrong unless they sit down and scribble numbers on papers very carefully (and slowly).

Re: Classic WTF: SuperRand

2012-12-26 19:53 • by BillTheGeek (unregistered)
397996 in reply to 397992
Dan:
Writing a good random number generator from scratch is very tricky. However using the one built into your language is not. Knowing these 2 facts is not particularly tricky. A little Googling before you even attempt to build your own would be warranted.


I mostly agree with that. Properly using a random number generator (RNG) can be tricky in some instances. One easy way to fail is to improperly seed the RNG (which includes not seeding it at all and reseeding several times during use, as SuperRand() does). Another is to share the same seed for multiple "streams" of numbers. Yet another is to use a built-in RNG for a cryptographic hash function.

Most of the time, improper use of an RNG is not noticed because many applications do not need "full-strength" randomness and because few developers know how to test for randomness in a set of output data.

Re: Classic WTF: SuperRand

2012-12-26 20:02 • by BillTheGeek (unregistered)
397997 in reply to 397993
Norman Diamond:
BillTheGeek:
The worst random number generator I have personally encountered had a period of six (!) unique numbers, and it was written by a friend of mine who is otherwise a good programmer.
You can name your friend. After all, he humbly published his mistake in the second volume of The Art of Computer Programming, and decently labelled it "Algorithm K".

(And yes I know that if I wrote an "Algorithm D" it would be worse.)


My friend is not named Donald Knuth, and he has never published any of his work-related code. When I wrote "personally encountered," I meant actual source files in the actual development environment, not something I read in a book.

Re: Classic WTF: SuperRand

2012-12-26 20:50 • by Worf (unregistered)
397998 in reply to 397994
Daniel:
Henry:
So the possibility of wrecking my car and myself by going an unsafe speed doesn't count as "deterrence"?


For anybody with any sense, yes, it would. For the sort of morons who actually speed clearly it does not as is demonstrated by the fact that they do speed and that a lot of them crash, quite a lot of them into other people. In many cases they are driving a car they just stole and/or they are too drunk to care.

Deterrence is fine for dealing with people who have enough sense to be deterred, either from the outset or maybe after a few tickets if they are a bit slow on the uptake. For the real morons traffic cops are there to get them arrested, off the roads and banned from driving and to get any stolen cars returned to their rightful owners before they get too badly damaged.


An interesting thing about traffic accidents - those who cause them usually get away with them, while the victims are the one who suffer.

Take speeding - unless you crash into a tree, most of the accidents involve other vehicles and pedestrians and cyclists. Well, if it's a pedestrian or cyclist, you can bet they'll have serious injuries that are probably lifelong, if not death. The speeder? A dented car and can walk away from it.

If you T-Bone someone, well, the guy getting T-boned gets injured (sometimes fatally), their passenger gets seriously hurt, and the guy running the light or speeding through? Superficial injuries.

Ditto drunken driving or texting/using a cellphone - more than likely the person who suffers in an accident is not the person who undertook the activity. (It's gotten so far that there are jurisdictions consider manslaughter charges now - previously killing someone with a car is generally a minor offense).

In most other activities, the risk is almost entirely borne by the risk-taker. Except when driving, where the risk is borne by everyone else - very little to the actual risk-taker themselves.

Think about that the next time you speed - it ain't you that's gonna get hurt, but if your family's not in the car with you while you speed, they could get run over or hit by a speeder and injured.

Re: Classic WTF: SuperRand

2012-12-26 21:19 • by Bill C. (unregistered)
I'm not big on law enforcement, but I could do the SuperRandy stuff.

Re: Classic WTF: SuperRand

2012-12-27 00:00 • by Simon (unregistered)
398000 in reply to 397975
Henry:
So the possibility of wrecking my car and myself by going an unsafe speed doesn't count as "deterrence"?


Oddly enough, no. There are a lot of motorists out there who don't seem to give a thought to their own safety (never mind that of anyone else on the road), but *do* respond to being fined for it. It doesn't make sense, but that's the way the world works...

Re: Classic WTF: SuperRand

2012-12-27 03:54 • by Soviut
398003 in reply to 397965
Henry:
Cops don't like speed traps? Neither do we. So why do they exist?


I'm a pedestrian. I love them.

Re: Classic WTF: SuperRand

2012-12-27 04:43 • by tim (unregistered)
398004 in reply to 397965
Henry:
Cops don't like speed traps? Neither do we. So why do they exist?

Thanks but I love speed traps. It's a voluntary tax and I choose not to pay it by driving within the limit. If you pay it, thanks for keeping my tax bill down.

Re: Classic WTF: SuperRand

2012-12-27 05:04 • by John Hensley (unregistered)
398005 in reply to 397997
BillTheGeek:

My friend is not named Donald Knuth, and he has never published any of his work-related code. When I wrote "personally encountered," I meant actual source files in the actual development environment, not something I read in a book.

"Development environment"? Pssh, I encountered a random number generator on the way home.

Re: Classic WTF: SuperRand

2012-12-27 05:12 • by alvatrus (unregistered)
And then the original developer comes around, sees his commented-out code and in a fit of rage puts in his original code, screaming that those incompetents ruined his perfect algorithm.
I've seen it all before: *never* leave in bad code. Someone is bound to reuse it, or use the pattern because it's much simpler than the example of working code.

Re: Classic WTF: SuperRand

2012-12-27 05:42 • by toshir0
398007 in reply to 398004
tim:
Henry:
Cops don't like speed traps? Neither do we. So why do they exist?

Thanks but I love speed traps. It's a voluntary tax and I choose not to pay it by driving within the limit. If you pay it, thanks for keeping my tax bill down.
+1 ^^

Thx Henry, You're too kind !

Re: Classic WTF: SuperRand

2012-12-27 06:11 • by Matt Westwood
398008 in reply to 397963
Ralph:
It is delightful the way he explains "adding them together will improve the randomness by" and then stops without his justification. I'd love to know what he was thinking, but perhaps his brain itself went blank at this same point.


He was asked by his boss: "Adding them together will improve the randomness by ...? Don't forget to add that to the comment above the code, like I reminded you yesterday."

Re: Classic WTF: SuperRand

2012-12-27 06:13 • by Matt Westwood
398009 in reply to 397975
Henry:
Brendan Kidwell:
Henry:
Cops don't like speed traps? Neither do we. So why do they exist?
Gotta have some form of deterrence.
So the possibility of wrecking my car and myself by going an unsafe speed doesn't count as "deterrence"?

I've evaluated the probability of harm that will come to me as a result of going ___ miles per hour and concluded that it is an acceptable risk. But, the possibility of encountering the cop must be a higher risk, otherwise it would not deter me. This means the cop himself, and the various threats that he represents, are more dangerous than the original "offense" of speeding.
Brendan Kidwell:
practically free revenue for the town or local police force.
Aaah, now you've got it. Legalized highway robbery, plain and simple.

If you don't want to pay speeding fines, don't fucking speed, you cunt.

Re: Classic WTF: SuperRand

2012-12-27 06:17 • by Matt Westwood
398010 in reply to 397984
Blakeyrat:
Speedin isn't a crime if those other people are tôo scared they should piss off its survival of the fittest either slam with the best or jam with the rest and if you can't step it up on the road the you're a Slomo dead weight and you might as well go kill yourself cuz or only gonna get juiced and jammed


I've encountered this shithead in the fora and he's an obnoxious cunt there as well. Someone give him a gun, he might shoot his head off.

Re: Classic WTF: SuperRand

2012-12-27 07:36 • by Frank Lee (unregistered)
In 30 years of driving I've never caused an accident, much less hurt someone. But I break the speed limit almost every day.

And I'm willing to bet you do too.

Re: Classic WTF: SuperRand

2012-12-27 08:04 • by Blakeyrat (unregistered)
Your mum's spam
« PrevPage 1 | Page 2Next »

Add Comment