Topic: Defect report: inconsistencies in the definitions of rand()
Author: kuyper@wizard.net ("James Kuyper Jr.")
Date: Sat, 11 Jan 2003 17:28:15 +0000 (UTC) Raw View
Allan W wrote:
....
> As I understand it, your conflict can be boiled down to this:
>
> Imagine that some program needs rand(), but should not use srand()
> for some reason -- perhaps because the results need to be
> repeatable. Bad programmers don’t even know about srand(), so of
> course they won’t use it. Is it possible for a bad programmer to
> write a good program?
That's not quite the situation I'm talking about. You can get repeatable
results using srand(). I'm saying that sometimes srand() isn't
necessary. However, it's never necessary to NOT use srand().
> You're both making an unwarranted assumption: that there are good
> programmers and bad programmers, at least with respect to their
I think you're reading too much into the discussion. I certainly wasn't
thinking of "good programmer" vs. "bad programmer" as a dichotomy, nor
as a merely 1-dimensional continuum, and I doubt that Pete was making
those mistakes, either.
....
> My point here (yes, I do have a point!) is that it's ridiculous to say
> things like, "[They wrote code that] happens purely by chance to ...be
> code that's right, even though they don't know enough about the system
> to ensure that result." Non-trivial code never happens by accident. Given
> a 1-hour lecture on the topic of rand/srand, I can produce programmers
> who can indeed ensure that their code is absolutely right in that respect.
You'd be amazed. Entry level programmers can achieve amazing amounts of
useful code, just by copying working code that they don't fully
understand, and fiddling with it until it produces the results that they
need to get. I'd never recommend this approach, but it does actually
work. I know this from personal experience, because my company has hired
a lot of entry-level programmers. They usually end up coming to me for help.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: kuyper@wizard.net ("James Kuyper Jr.")
Date: Fri, 10 Jan 2003 04:16:27 +0000 (UTC) Raw View
Pete Becker wrote:
> "James Kuyper Jr." wrote:
>
>>Pete Becker wrote:
....
>>>No. You must know about srand in order to use rand correctly.
>>
>>It's quite possible to accidentally use rand() correctly without that
>>knowledge.
>
>
> There are many things that sloppy programmers can do by accident. There
> is very little that they can do right. They might produce code that runs
> the way they expect. There's a long distance from there to code that's
> right.
It isn't necessarily a long distance, or even any distance at all.
Sometimes code which runs exactly the way they expect, happens purely by
chance to also be code that's right, even though they don't know enough
about the system to ensure that result.
In the case of rand(), I'd even argue that it's pretty easy to do so.
I've seen quite a few situations where non-default seed initialization
was completely unimportant. Not serious scientific simulations, of
course - but not all uses of rand() are as demanding as that. In my
experience, most of the situations where non-default seed initialization
is called for, are also situations that call for a more reliably useful
randomizer than rand().
>>There are contexts where srand() is not needed, and a
>>programmer would not be penalized by his ignorance of srand() if he
>>happened to be writing code for one of those contexts.
>>
>
>
> Nobody suggested penalizing anyone.
I'm not talking about any kind of externally imposed penalty. I'm
referring to the penalty that inherently occurs when you are ignorant of
something you NEED to know. My point was, that it's perfectly possible
to use rand(), without using srand(), and suffer no such penalty. That
means that knowledge of srand() is not actually necessary; if it were,
then the penalty would be unavoidable.
> ... But how can a programmer who doesn't
> know about srand determine that it's not needed?
He doesn't; he can achieve correctness only by accident. I was rebutting
your claim that the knowledge was necessary to achieve correctness; it
isn't - in the absence of knowledge, an accident can achieve the same thing.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: petebecker@acm.org (Pete Becker)
Date: Sat, 11 Jan 2003 08:02:53 +0000 (UTC) Raw View
===================================== MODERATOR'S COMMENT:
Please bring this thread back to something related to C++ standardization. Or consider moving it to email.
===================================== END OF MODERATOR'S COMMENT
"James Kuyper Jr." wrote:
>
> Pete Becker wrote:
> > ... But how can a programmer who doesn't
> > know about srand determine that it's not needed?
>
> He doesn't; he can achieve correctness only by accident. I was rebutting
> your claim that the knowledge was necessary to achieve correctness;
Then you've failed.
> it
> isn't - in the absence of knowledge, an accident can achieve the same thing.
>
Nope. As I said before, an accident can create code that works
correctly. That's not the same as using rand correctly, which requires
understanding it.
--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: petebecker@acm.org (Pete Becker)
Date: Thu, 9 Jan 2003 18:57:40 +0000 (UTC) Raw View
"James Kuyper Jr." wrote:
>
> Pete Becker wrote:
> > Tom Hyer wrote:
> ....
> >>The aim is that users who do not care about the state can easily
> >>ignore it.
> >
> >
> > No. You must know about srand in order to use rand correctly.
>
> It's quite possible to accidentally use rand() correctly without that
> knowledge.
There are many things that sloppy programmers can do by accident. There
is very little that they can do right. They might produce code that runs
the way they expect. There's a long distance from there to code that's
right.
> There are contexts where srand() is not needed, and a
> programmer would not be penalized by his ignorance of srand() if he
> happened to be writing code for one of those contexts.
>
Nobody suggested penalizing anyone. But how can a programmer who doesn't
know about srand determine that it's not needed?
--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]