Uploaded image for project: 'Commons RNG'
  1. Commons RNG
  2. RNG-57

CachedUniformRandomProvider for nextBoolean() and nextInt()

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Implemented
    • None
    • 1.2
    • core

    Description

      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.

      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...));
      

      The implementation should be speed tested to determine the benefit for nextBoolean() and if nextInt() can be improved for LongProviders.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              aherbert Alex Herbert
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: