On Sun, 26 Oct 2008 02:41:29 -0700, Peter Morris
<mr*********@spamgmail.comwrote:
>It is something that is known for all languages and
technologies.
I don't think that is quite accurate :-)
Well, "all" might be overreaching. But "all broadly used" probably isn't,
especially if one is specifically discussing using the common technique of
seeding a random number generator with some time value, and especially if
we limit the discussion to Windows (where we know in advance the
limitations of retrieving a time value).
All pseudo-random-number generators require a seed, and the two most
common ways to provide that seed are to default to 0 and to use a time
value. In either case, repeatedly creating a new generator is always
wrong; to produce a series of random numbers, one should always initialize
the generator once, and then use the same one repeatedly.
Obviously if the seed is always the same, creating a new generator for
each new random number is wrong. When the seed is 0, that's a trivial
case to demonstrate. But it's also true that on the broadly-used PC
operating systems (including Windows), functions to retrieve the current
time have limited precision and if called too quickly in succession will
actually return the same value.
I think the most important lesson is that a person ought to read the
documentation when using some API. The caveat "FTM" quoted is provided in
multiple places in the documentation for Random, including the main class
page and (as he points out) the page documenting the constructor. Even a
person who wasn't familiar with the general issue would, given that
documentation, be able to learn about the specific caveats regarding the
Random class. Had they bothered to read the documentation, of course.
Which is a very long way of saying that Arne's comment might not have been
literally true, but I doubt that someone can come up with a
counter-example that involves a random-number generator in common use and
it's not like the issue described in this thread should be some sort of
remarkable revelation to anyone.
Pete