commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ted Dunning <>
Subject Re: [math] inconsistent use of random generators
Date Wed, 17 Nov 2010 08:38:16 GMT
On Wed, Nov 17, 2010 at 12:19 AM, Luc Maisonobe <>wrote:

> > In Mahout, we did this by having a static method in a utility class for
> > getting a standard generator for either testing or normal operation.
>  This
> > has turned out very well.
> It's a very good idea for production code, but I am not sure I
> understand it's use for test code. Doesn't that induce problems when new
> tests are included which change the running order of the tests or when
> only one test is run ?

No.  The seed is constant.  This means that the test gets the same results
no matter what.

Moreover, since the generator is obtained in the same way, and it is the
utility method that checks
to see if a test is being run, exactly the same production code paths are
exercised in production and
test mode.

> In these cases the current state for the
> generator will not be the same in each situation. Do tests reseed the
> generator when they start ?

The utility returns a consistently seeded generator if running a test.  The
code using the generator just asks
the utility class for a generator and doesn't know if it is seeded for a
test or not.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message