commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gilles (JIRA)" <>
Subject [jira] [Commented] (RNG-57) CachedUniformRandomProvider for nextBoolean() and nextInt()
Date Tue, 09 Oct 2018 00:38:00 GMT


Gilles commented on RNG-57:

bq. Apologies in advance for the long post.

A very interesting analysis (and a useful appendix to the user guide perhaps).
Here on JIRA, it's not easy to follow the discussion (e.g. wide tables are not displayed in
their entirety).
Codes (that would produce the above tables) could go in the {{commons-rng-examples}} module.

bq. An alternative approach would be to reduce the number of tests per RNG. These could be
limited to nextBytes and either nextInt or nextLong depending on the type of provider.

Did I understand correctly that you propose to
# test the randomness uniformity of each of the implementations of {{IntProvider}} (resp.
{{LongProvider}}) through exercising {{nextInt()}} (resp. {{nextLong()}}) only, and
# test the rest of the methods defined in {{UniformRandomProvider}} using {{SecureRandom}}
as the source?

bq. It is not very convenient for local development though as builds will fail a fair amount.

JUnit is set to rerun failing tests (once in the current config); it seems to work fine for
module {{commons-rng-sampling}}, where the distribution tests do indeed use random seeds.

> CachedUniformRandomProvider for nextBoolean() and nextInt()
> -----------------------------------------------------------
>                 Key: RNG-57
>                 URL:
>             Project: Commons RNG
>          Issue Type: Improvement
>          Components: sampling
>    Affects Versions: 1.2
>            Reporter: Alex D Herbert
>            Priority: Minor
>              Labels: performance
> Implement a wrapper around a {{UniformRandomProvider}} that can cache the underlying
source of random bytes for use in the methods {{nextBoolean()}} and {{nextInt()}} (in the
case of {{LongProvider}}). E.g.
> {code:java}
> LongProvider provider = RandomSource.create(RandomSource.SPLIT_MIX_64);
> CachedLongProvider rng = new CachedLongProvider(provider);
> // Uses cached nextLong() 64 times
> rng.nextBoolean();
> // Uses cached nextLong() twice
> rng.nextInt();
> IntProvider provider = RandomSource.create(RandomSource.KISS);
> CachedIntProvider rng2 = new CachedIntProvider(provider);
> // Uses cached nextInt() 32 times
> rng2.nextBoolean();
> // This could be wrapped by a factory method:
> UniformRandomProvider rng = CachedUniformRandomProviderFactory.wrap(
>         // Any supported source: IntProvider or LongProvider
>         RandomSource.create(RandomSource...));
> {code}
> The implementation should be speed tested to determine the benefit for {{nextBoolean()}}
and if {{nextInt()}} can be improved for {{LongProviders}}.

This message was sent by Atlassian JIRA

View raw message