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

JDKRandom to allow restore state when saved from a different instance

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Implemented
    • 1.2
    • 1.3
    • core
    • None

    Description

      Currently the size of the serialized state of the java.util.Random used by JDKRandom is saved to the instance when the state is saved. Thus the state cannot be used to restore a different instance of the same class. This breaks the contract of the RestorableUniformRandomProvider as the state should be applicable to a different instance of the same class.

      Fix this test to work:

      @Test
      public void testRestoreToNewInstance()  {
          final long seed = 8796746234L;
          final JDKRandom rng1 = new JDKRandom(seed);
          final JDKRandom rng2 = new JDKRandom(seed + 1);
      
          final RandomProviderState state = rng1.saveState();
          rng2.restoreState(state);
      
          final int numRepeats = 1000;
          for (int r = 0; r < numRepeats; r++) {
              Assert.assertEquals(r + " nextInt", rng1.nextInt(), rng2.nextInt());
          }
      }
      

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h