commons-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r995697 [11/14] - in /websites/production/commons/content/proper/commons-rng: ./ apidocs/ apidocs/org/apache/commons/rng/ apidocs/org/apache/commons/rng/class-use/ apidocs/org/apache/commons/rng/internal/ apidocs/org/apache/commons/rng/inte...
Date Mon, 22 Aug 2016 22:01:59 GMT
Modified: websites/production/commons/content/proper/commons-rng/xref-test/org/apache/commons/rng/ProvidersCommonParametricTest.html
==============================================================================
--- websites/production/commons/content/proper/commons-rng/xref-test/org/apache/commons/rng/ProvidersCommonParametricTest.html (original)
+++ websites/production/commons/content/proper/commons-rng/xref-test/org/apache/commons/rng/ProvidersCommonParametricTest.html Mon Aug 22 22:01:58 2016
@@ -300,7 +300,7 @@
 <a class="jxr_linenumber" name="L292" href="#L292">292</a>     }
 <a class="jxr_linenumber" name="L293" href="#L293">293</a> 
 <a class="jxr_linenumber" name="L294" href="#L294">294</a>     @Test
-<a class="jxr_linenumber" name="L295" href="#L295">295</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> testSerializedState()
+<a class="jxr_linenumber" name="L295" href="#L295">295</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> testSerializingState()
 <a class="jxr_linenumber" name="L296" href="#L296">296</a>         <strong class="jxr_keyword">throws</strong> IOException,
 <a class="jxr_linenumber" name="L297" href="#L297">297</a>                ClassNotFoundException {
 <a class="jxr_linenumber" name="L298" href="#L298">298</a>         <em class="jxr_comment">// Large "n" is not necessary here as we only test the serialization.</em>
@@ -310,7 +310,7 @@
 <a class="jxr_linenumber" name="L302" href="#L302">302</a>         <strong class="jxr_keyword">final</strong> RandomSource.State stateOrig = RandomSource.saveState(generator);
 <a class="jxr_linenumber" name="L303" href="#L303">303</a>         ByteArrayOutputStream bos = <strong class="jxr_keyword">new</strong> ByteArrayOutputStream();
 <a class="jxr_linenumber" name="L304" href="#L304">304</a>         ObjectOutputStream oos = <strong class="jxr_keyword">new</strong> ObjectOutputStream(bos);
-<a class="jxr_linenumber" name="L305" href="#L305">305</a>         oos.writeObject(stateOrig);
+<a class="jxr_linenumber" name="L305" href="#L305">305</a>         oos.writeObject(stateOrig.getState());
 <a class="jxr_linenumber" name="L306" href="#L306">306</a> 
 <a class="jxr_linenumber" name="L307" href="#L307">307</a>         <em class="jxr_comment">// Store some values.</em>
 <a class="jxr_linenumber" name="L308" href="#L308">308</a>         <strong class="jxr_keyword">final</strong> List&lt;Number&gt; listOrig = makeList(n);
@@ -323,7 +323,7 @@
 <a class="jxr_linenumber" name="L315" href="#L315">315</a>         <em class="jxr_comment">// Retrieve from serialized stream.</em>
 <a class="jxr_linenumber" name="L316" href="#L316">316</a>         ByteArrayInputStream bis = <strong class="jxr_keyword">new</strong> ByteArrayInputStream(bos.toByteArray());
 <a class="jxr_linenumber" name="L317" href="#L317">317</a>         ObjectInputStream ois = <strong class="jxr_keyword">new</strong> ObjectInputStream(bis);
-<a class="jxr_linenumber" name="L318" href="#L318">318</a>         <strong class="jxr_keyword">final</strong> RandomSource.State stateNew = (RandomSource.State) ois.readObject();
+<a class="jxr_linenumber" name="L318" href="#L318">318</a>         <strong class="jxr_keyword">final</strong> RandomSource.State stateNew = <strong class="jxr_keyword">new</strong> RandomSource.State((byte[]) ois.readObject());
 <a class="jxr_linenumber" name="L319" href="#L319">319</a> 
 <a class="jxr_linenumber" name="L320" href="#L320">320</a>         Assert.assertTrue(stateOrig != stateNew);
 <a class="jxr_linenumber" name="L321" href="#L321">321</a> 
@@ -338,358 +338,352 @@
 <a class="jxr_linenumber" name="L330" href="#L330">330</a>         Assert.assertTrue(listOrig.equals(listReplay));
 <a class="jxr_linenumber" name="L331" href="#L331">331</a>     }
 <a class="jxr_linenumber" name="L332" href="#L332">332</a> 
-<a class="jxr_linenumber" name="L333" href="#L333">333</a>     @Test(expected=ClassCastException.<strong class="jxr_keyword">class</strong>)
-<a class="jxr_linenumber" name="L334" href="#L334">334</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> testStateWrongClass() {
-<a class="jxr_linenumber" name="L335" href="#L335">335</a>         <em class="jxr_comment">// Try to restore with an invalid state.</em>
-<a class="jxr_linenumber" name="L336" href="#L336">336</a>         RandomSource.restoreState(generator, <strong class="jxr_keyword">new</strong> RandomSource.State() {});
-<a class="jxr_linenumber" name="L337" href="#L337">337</a>     }
-<a class="jxr_linenumber" name="L338" href="#L338">338</a> 
-<a class="jxr_linenumber" name="L339" href="#L339">339</a>     @Test(expected=IllegalArgumentException.<strong class="jxr_keyword">class</strong>)
-<a class="jxr_linenumber" name="L340" href="#L340">340</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> testStateWrongSize() {
-<a class="jxr_linenumber" name="L341" href="#L341">341</a>         <em class="jxr_comment">// We don't know what is the state of "java.lang.Random": skipping.</em>
-<a class="jxr_linenumber" name="L342" href="#L342">342</a>         Assume.assumeTrue(generator.toString().indexOf(<span class="jxr_string">"JDKRandom"</span>) == -1);
-<a class="jxr_linenumber" name="L343" href="#L343">343</a> 
-<a class="jxr_linenumber" name="L344" href="#L344">344</a>         <strong class="jxr_keyword">final</strong> RandomSource.State state = RandomSource.saveState(<strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/commons/rng/ProvidersCommonParametricTest.html">DummyGenerator</a>());
-<a class="jxr_linenumber" name="L345" href="#L345">345</a>         <em class="jxr_comment">// Try to restore with an invalid state (wrong size).</em>
-<a class="jxr_linenumber" name="L346" href="#L346">346</a>         RandomSource.restoreState(generator, state);
-<a class="jxr_linenumber" name="L347" href="#L347">347</a>     }
-<a class="jxr_linenumber" name="L348" href="#L348">348</a> 
-<a class="jxr_linenumber" name="L349" href="#L349">349</a>     <em class="jxr_comment">///// Support methods below.</em>
-<a class="jxr_linenumber" name="L350" href="#L350">350</a> 
-<a class="jxr_linenumber" name="L351" href="#L351">351</a>     <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="L352" href="#L352">352</a> <em class="jxr_javadoccomment">     * Populates a list with random numbers.</em>
-<a class="jxr_linenumber" name="L353" href="#L353">353</a> <em class="jxr_javadoccomment">     *</em>
-<a class="jxr_linenumber" name="L354" href="#L354">354</a> <em class="jxr_javadoccomment">     * @param n Loop counter.</em>
-<a class="jxr_linenumber" name="L355" href="#L355">355</a> <em class="jxr_javadoccomment">     * @return a list containing {@code 11 * n} random numbers.</em>
-<a class="jxr_linenumber" name="L356" href="#L356">356</a> <em class="jxr_javadoccomment">     */</em>
-<a class="jxr_linenumber" name="L357" href="#L357">357</a>     <strong class="jxr_keyword">private</strong> List&lt;Number&gt; makeList(<strong class="jxr_keyword">int</strong> n) {
-<a class="jxr_linenumber" name="L358" href="#L358">358</a>         <strong class="jxr_keyword">final</strong> List&lt;Number&gt; list = <strong class="jxr_keyword">new</strong> ArrayList&lt;Number&gt;();
-<a class="jxr_linenumber" name="L359" href="#L359">359</a> 
-<a class="jxr_linenumber" name="L360" href="#L360">360</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; n; i++) {
-<a class="jxr_linenumber" name="L361" href="#L361">361</a>             <em class="jxr_comment">// Append 11 values.</em>
-<a class="jxr_linenumber" name="L362" href="#L362">362</a>             list.add(generator.nextInt());
-<a class="jxr_linenumber" name="L363" href="#L363">363</a>             list.add(generator.nextInt(21));
-<a class="jxr_linenumber" name="L364" href="#L364">364</a>             list.add(generator.nextInt(436));
-<a class="jxr_linenumber" name="L365" href="#L365">365</a>             list.add(generator.nextLong());
-<a class="jxr_linenumber" name="L366" href="#L366">366</a>             list.add(generator.nextLong(157894));
-<a class="jxr_linenumber" name="L367" href="#L367">367</a>             list.add(generator.nextLong(5745833));
-<a class="jxr_linenumber" name="L368" href="#L368">368</a>             list.add(generator.nextFloat());
-<a class="jxr_linenumber" name="L369" href="#L369">369</a>             list.add(generator.nextFloat());
-<a class="jxr_linenumber" name="L370" href="#L370">370</a>             list.add(generator.nextDouble());
-<a class="jxr_linenumber" name="L371" href="#L371">371</a>             list.add(generator.nextDouble());
-<a class="jxr_linenumber" name="L372" href="#L372">372</a>             list.add(generator.nextDouble());
-<a class="jxr_linenumber" name="L373" href="#L373">373</a>         }
-<a class="jxr_linenumber" name="L374" href="#L374">374</a> 
-<a class="jxr_linenumber" name="L375" href="#L375">375</a>         <strong class="jxr_keyword">return</strong> list;
-<a class="jxr_linenumber" name="L376" href="#L376">376</a>     }
-<a class="jxr_linenumber" name="L377" href="#L377">377</a> 
-<a class="jxr_linenumber" name="L378" href="#L378">378</a>     <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="L379" href="#L379">379</a> <em class="jxr_javadoccomment">     * Checks that the generator values can be placed into 256 bins with</em>
-<a class="jxr_linenumber" name="L380" href="#L380">380</a> <em class="jxr_javadoccomment">     * approximately equal number of counts.</em>
-<a class="jxr_linenumber" name="L381" href="#L381">381</a> <em class="jxr_javadoccomment">     * Test allows to select only part of the buffer for performing the</em>
-<a class="jxr_linenumber" name="L382" href="#L382">382</a> <em class="jxr_javadoccomment">     * statistics.</em>
-<a class="jxr_linenumber" name="L383" href="#L383">383</a> <em class="jxr_javadoccomment">     *</em>
-<a class="jxr_linenumber" name="L384" href="#L384">384</a> <em class="jxr_javadoccomment">     * @param buffer Buffer to be filled.</em>
-<a class="jxr_linenumber" name="L385" href="#L385">385</a> <em class="jxr_javadoccomment">     * @param first First element (included) of {@code buffer} range for</em>
-<a class="jxr_linenumber" name="L386" href="#L386">386</a> <em class="jxr_javadoccomment">     * which statistics must be taken into account.</em>
-<a class="jxr_linenumber" name="L387" href="#L387">387</a> <em class="jxr_javadoccomment">     * @param last Last element (excluded) of {@code buffer} range for</em>
-<a class="jxr_linenumber" name="L388" href="#L388">388</a> <em class="jxr_javadoccomment">     * which statistics must be taken into account.</em>
-<a class="jxr_linenumber" name="L389" href="#L389">389</a> <em class="jxr_javadoccomment">     * @param nextMethod Method that fills the given {@code buffer}.</em>
-<a class="jxr_linenumber" name="L390" href="#L390">390</a> <em class="jxr_javadoccomment">     * @return {@code true} if the distribution is uniform.</em>
-<a class="jxr_linenumber" name="L391" href="#L391">391</a> <em class="jxr_javadoccomment">     */</em>
-<a class="jxr_linenumber" name="L392" href="#L392">392</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">boolean</strong> isUniformNextBytes(byte[] buffer,
-<a class="jxr_linenumber" name="L393" href="#L393">393</a>                                        <strong class="jxr_keyword">int</strong> first,
-<a class="jxr_linenumber" name="L394" href="#L394">394</a>                                        <strong class="jxr_keyword">int</strong> last,
-<a class="jxr_linenumber" name="L395" href="#L395">395</a>                                        Runnable nextMethod) {
-<a class="jxr_linenumber" name="L396" href="#L396">396</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">int</strong> sampleSize = 10000;
-<a class="jxr_linenumber" name="L397" href="#L397">397</a> 
-<a class="jxr_linenumber" name="L398" href="#L398">398</a>         <em class="jxr_comment">// Number of possible values (do not change).</em>
-<a class="jxr_linenumber" name="L399" href="#L399">399</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">int</strong> byteRange = 256;
-<a class="jxr_linenumber" name="L400" href="#L400">400</a>         <em class="jxr_comment">// Chi-square critical value with 256 degrees of freedom</em>
-<a class="jxr_linenumber" name="L401" href="#L401">401</a>         <em class="jxr_comment">// and 1% significance level.</em>
-<a class="jxr_linenumber" name="L402" href="#L402">402</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> chi2CriticalValue = 311.560343;
-<a class="jxr_linenumber" name="L403" href="#L403">403</a>         <em class="jxr_comment">// To transform a byte value into its bin index.</em>
-<a class="jxr_linenumber" name="L404" href="#L404">404</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">int</strong> byteRangeOffset = 128;
-<a class="jxr_linenumber" name="L405" href="#L405">405</a> 
-<a class="jxr_linenumber" name="L406" href="#L406">406</a>         <em class="jxr_comment">// Bins.</em>
-<a class="jxr_linenumber" name="L407" href="#L407">407</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">long</strong>[] observed = <strong class="jxr_keyword">new</strong> <strong class="jxr_keyword">long</strong>[byteRange];
-<a class="jxr_linenumber" name="L408" href="#L408">408</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong>[] expected = <strong class="jxr_keyword">new</strong> <strong class="jxr_keyword">double</strong>[byteRange];
-<a class="jxr_linenumber" name="L409" href="#L409">409</a> 
-<a class="jxr_linenumber" name="L410" href="#L410">410</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; byteRange; i++) {
-<a class="jxr_linenumber" name="L411" href="#L411">411</a>             expected[i] = sampleSize * (last - first) / (<strong class="jxr_keyword">double</strong>) byteRange;
-<a class="jxr_linenumber" name="L412" href="#L412">412</a>         }
-<a class="jxr_linenumber" name="L413" href="#L413">413</a> 
-<a class="jxr_linenumber" name="L414" href="#L414">414</a>         <strong class="jxr_keyword">try</strong> {
-<a class="jxr_linenumber" name="L415" href="#L415">415</a>             <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> k = 0; k &lt; sampleSize; k++) {
-<a class="jxr_linenumber" name="L416" href="#L416">416</a>                 nextMethod.run();
-<a class="jxr_linenumber" name="L417" href="#L417">417</a> 
-<a class="jxr_linenumber" name="L418" href="#L418">418</a>                 <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = first; i &lt; last; i++) {
-<a class="jxr_linenumber" name="L419" href="#L419">419</a>                     <strong class="jxr_keyword">final</strong> byte b = buffer[i];
-<a class="jxr_linenumber" name="L420" href="#L420">420</a>                     ++observed[b + byteRangeOffset];
-<a class="jxr_linenumber" name="L421" href="#L421">421</a>                 }
-<a class="jxr_linenumber" name="L422" href="#L422">422</a>             }
-<a class="jxr_linenumber" name="L423" href="#L423">423</a>         } <strong class="jxr_keyword">catch</strong> (Exception e) {
-<a class="jxr_linenumber" name="L424" href="#L424">424</a>             <em class="jxr_comment">// Should never happen.</em>
-<a class="jxr_linenumber" name="L425" href="#L425">425</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> RuntimeException(<span class="jxr_string">"Unexpected"</span>);
-<a class="jxr_linenumber" name="L426" href="#L426">426</a>         }
-<a class="jxr_linenumber" name="L427" href="#L427">427</a> 
-<a class="jxr_linenumber" name="L428" href="#L428">428</a>         <em class="jxr_comment">// Compute chi-square.</em>
-<a class="jxr_linenumber" name="L429" href="#L429">429</a>         <strong class="jxr_keyword">double</strong> chi2 = 0;
-<a class="jxr_linenumber" name="L430" href="#L430">430</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> k = 0; k &lt; byteRange; k++) {
-<a class="jxr_linenumber" name="L431" href="#L431">431</a>             <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> diff = observed[k] - expected[k];
-<a class="jxr_linenumber" name="L432" href="#L432">432</a>             chi2 += diff * diff / expected[k];
-<a class="jxr_linenumber" name="L433" href="#L433">433</a>         }
-<a class="jxr_linenumber" name="L434" href="#L434">434</a> 
-<a class="jxr_linenumber" name="L435" href="#L435">435</a>         <em class="jxr_comment">// Statistics check.</em>
-<a class="jxr_linenumber" name="L436" href="#L436">436</a>         <strong class="jxr_keyword">return</strong> chi2 &lt; chi2CriticalValue;
-<a class="jxr_linenumber" name="L437" href="#L437">437</a>     }
-<a class="jxr_linenumber" name="L438" href="#L438">438</a> 
-<a class="jxr_linenumber" name="L439" href="#L439">439</a>     <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="L440" href="#L440">440</a> <em class="jxr_javadoccomment">     * Checks that the generator values can be placed into 2 bins with</em>
-<a class="jxr_linenumber" name="L441" href="#L441">441</a> <em class="jxr_javadoccomment">     * approximately equal number of counts.</em>
-<a class="jxr_linenumber" name="L442" href="#L442">442</a> <em class="jxr_javadoccomment">     * The test uses the expectation from a fixed-step "random walk".</em>
-<a class="jxr_linenumber" name="L443" href="#L443">443</a> <em class="jxr_javadoccomment">     *</em>
-<a class="jxr_linenumber" name="L444" href="#L444">444</a> <em class="jxr_javadoccomment">     * @param nextMethod Method that returns {@code true} if the generated</em>
-<a class="jxr_linenumber" name="L445" href="#L445">445</a> <em class="jxr_javadoccomment">     * values are to be placed in the first bin, {@code false} if it must</em>
-<a class="jxr_linenumber" name="L446" href="#L446">446</a> <em class="jxr_javadoccomment">     * go to the second bin.</em>
-<a class="jxr_linenumber" name="L447" href="#L447">447</a> <em class="jxr_javadoccomment">     */</em>
-<a class="jxr_linenumber" name="L448" href="#L448">448</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> checkRandomWalk(<strong class="jxr_keyword">int</strong> sampleSize,
-<a class="jxr_linenumber" name="L449" href="#L449">449</a>                                  Callable&lt;Boolean&gt; nextMethod) {
-<a class="jxr_linenumber" name="L450" href="#L450">450</a>         <strong class="jxr_keyword">int</strong> walk = 0;
-<a class="jxr_linenumber" name="L451" href="#L451">451</a> 
-<a class="jxr_linenumber" name="L452" href="#L452">452</a>         <strong class="jxr_keyword">try</strong> {
-<a class="jxr_linenumber" name="L453" href="#L453">453</a>             <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> k = 0; k &lt; sampleSize; ++k) {
-<a class="jxr_linenumber" name="L454" href="#L454">454</a>                 <strong class="jxr_keyword">if</strong> (nextMethod.call()) {
-<a class="jxr_linenumber" name="L455" href="#L455">455</a>                     ++walk;
-<a class="jxr_linenumber" name="L456" href="#L456">456</a>                 } <strong class="jxr_keyword">else</strong> {
-<a class="jxr_linenumber" name="L457" href="#L457">457</a>                     --walk;
-<a class="jxr_linenumber" name="L458" href="#L458">458</a>                 }
-<a class="jxr_linenumber" name="L459" href="#L459">459</a>             }
-<a class="jxr_linenumber" name="L460" href="#L460">460</a>         } <strong class="jxr_keyword">catch</strong> (Exception e) {
-<a class="jxr_linenumber" name="L461" href="#L461">461</a>             <em class="jxr_comment">// Should never happen.</em>
-<a class="jxr_linenumber" name="L462" href="#L462">462</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> RuntimeException(<span class="jxr_string">"Unexpected"</span>);
-<a class="jxr_linenumber" name="L463" href="#L463">463</a>         }
-<a class="jxr_linenumber" name="L464" href="#L464">464</a> 
-<a class="jxr_linenumber" name="L465" href="#L465">465</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> actual = Math.abs(walk);
-<a class="jxr_linenumber" name="L466" href="#L466">466</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> max = Math.sqrt(sampleSize) * 2.576;
-<a class="jxr_linenumber" name="L467" href="#L467">467</a>         Assert.assertTrue(generator + <span class="jxr_string">": Walked too far astray: "</span> + actual +
-<a class="jxr_linenumber" name="L468" href="#L468">468</a>                           <span class="jxr_string">" &gt; "</span> + max +
-<a class="jxr_linenumber" name="L469" href="#L469">469</a>                           <span class="jxr_string">" (test will fail randomly about 1 in 100 times)"</span>,
-<a class="jxr_linenumber" name="L470" href="#L470">470</a>                           actual &lt; max);
-<a class="jxr_linenumber" name="L471" href="#L471">471</a>     }
-<a class="jxr_linenumber" name="L472" href="#L472">472</a> 
-<a class="jxr_linenumber" name="L473" href="#L473">473</a>     <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="L474" href="#L474">474</a> <em class="jxr_javadoccomment">     * Tests uniformity of the distribution produced by {@code nextInt(int)}.</em>
-<a class="jxr_linenumber" name="L475" href="#L475">475</a> <em class="jxr_javadoccomment">     *</em>
-<a class="jxr_linenumber" name="L476" href="#L476">476</a> <em class="jxr_javadoccomment">     * @param max Upper bound.</em>
-<a class="jxr_linenumber" name="L477" href="#L477">477</a> <em class="jxr_javadoccomment">     * @param sampleSize Number of random values generated.</em>
-<a class="jxr_linenumber" name="L478" href="#L478">478</a> <em class="jxr_javadoccomment">     */</em>
-<a class="jxr_linenumber" name="L479" href="#L479">479</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> checkNextIntegerInRange(<strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">int</strong> max,
-<a class="jxr_linenumber" name="L480" href="#L480">480</a>                                          <strong class="jxr_keyword">int</strong> sampleSize) {
-<a class="jxr_linenumber" name="L481" href="#L481">481</a>         <strong class="jxr_keyword">final</strong> Callable&lt;Integer&gt; nextMethod = <strong class="jxr_keyword">new</strong> Callable&lt;Integer&gt;() {
-<a class="jxr_linenumber" name="L482" href="#L482">482</a>             @Override
-<a class="jxr_linenumber" name="L483" href="#L483">483</a>             <strong class="jxr_keyword">public</strong> Integer call() <strong class="jxr_keyword">throws</strong> Exception {
-<a class="jxr_linenumber" name="L484" href="#L484">484</a>                 <strong class="jxr_keyword">return</strong> generator.nextInt(max);
-<a class="jxr_linenumber" name="L485" href="#L485">485</a>             }
-<a class="jxr_linenumber" name="L486" href="#L486">486</a>         };
-<a class="jxr_linenumber" name="L487" href="#L487">487</a> 
-<a class="jxr_linenumber" name="L488" href="#L488">488</a>         checkNextInRange(max, sampleSize, nextMethod);
-<a class="jxr_linenumber" name="L489" href="#L489">489</a>     }
-<a class="jxr_linenumber" name="L490" href="#L490">490</a> 
-<a class="jxr_linenumber" name="L491" href="#L491">491</a>     <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="L492" href="#L492">492</a> <em class="jxr_javadoccomment">     * Tests uniformity of the distribution produced by {@code nextLong(long)}.</em>
-<a class="jxr_linenumber" name="L493" href="#L493">493</a> <em class="jxr_javadoccomment">     *</em>
-<a class="jxr_linenumber" name="L494" href="#L494">494</a> <em class="jxr_javadoccomment">     * @param max Upper bound.</em>
-<a class="jxr_linenumber" name="L495" href="#L495">495</a> <em class="jxr_javadoccomment">     * @param sampleSize Number of random values generated.</em>
-<a class="jxr_linenumber" name="L496" href="#L496">496</a> <em class="jxr_javadoccomment">     */</em>
-<a class="jxr_linenumber" name="L497" href="#L497">497</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> checkNextLongInRange(<strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">long</strong> max,
-<a class="jxr_linenumber" name="L498" href="#L498">498</a>                                       <strong class="jxr_keyword">int</strong> sampleSize) {
-<a class="jxr_linenumber" name="L499" href="#L499">499</a>         <strong class="jxr_keyword">final</strong> Callable&lt;Long&gt; nextMethod = <strong class="jxr_keyword">new</strong> Callable&lt;Long&gt;() {
-<a class="jxr_linenumber" name="L500" href="#L500">500</a>             @Override
-<a class="jxr_linenumber" name="L501" href="#L501">501</a>             <strong class="jxr_keyword">public</strong> Long call() <strong class="jxr_keyword">throws</strong> Exception {
-<a class="jxr_linenumber" name="L502" href="#L502">502</a>                 <strong class="jxr_keyword">return</strong> generator.nextLong(max);
-<a class="jxr_linenumber" name="L503" href="#L503">503</a>             }
-<a class="jxr_linenumber" name="L504" href="#L504">504</a>         };
-<a class="jxr_linenumber" name="L505" href="#L505">505</a> 
-<a class="jxr_linenumber" name="L506" href="#L506">506</a>         checkNextInRange(max, sampleSize, nextMethod);
-<a class="jxr_linenumber" name="L507" href="#L507">507</a>     }
-<a class="jxr_linenumber" name="L508" href="#L508">508</a> 
-<a class="jxr_linenumber" name="L509" href="#L509">509</a>     <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="L510" href="#L510">510</a> <em class="jxr_javadoccomment">     * Tests uniformity of the distribution produced by {@code nextFloat()}.</em>
-<a class="jxr_linenumber" name="L511" href="#L511">511</a> <em class="jxr_javadoccomment">     *</em>
-<a class="jxr_linenumber" name="L512" href="#L512">512</a> <em class="jxr_javadoccomment">     * @param sampleSize Number of random values generated.</em>
-<a class="jxr_linenumber" name="L513" href="#L513">513</a> <em class="jxr_javadoccomment">     */</em>
-<a class="jxr_linenumber" name="L514" href="#L514">514</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> checkNextFloat(<strong class="jxr_keyword">int</strong> sampleSize) {
-<a class="jxr_linenumber" name="L515" href="#L515">515</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">int</strong> max = 1234;
-<a class="jxr_linenumber" name="L516" href="#L516">516</a>         <strong class="jxr_keyword">final</strong> Callable&lt;Integer&gt; nextMethod = <strong class="jxr_keyword">new</strong> Callable&lt;Integer&gt;() {
-<a class="jxr_linenumber" name="L517" href="#L517">517</a>             @Override
-<a class="jxr_linenumber" name="L518" href="#L518">518</a>             <strong class="jxr_keyword">public</strong> Integer call() <strong class="jxr_keyword">throws</strong> Exception {
-<a class="jxr_linenumber" name="L519" href="#L519">519</a>                 <strong class="jxr_keyword">return</strong> (<strong class="jxr_keyword">int</strong>) (max * generator.nextFloat());
-<a class="jxr_linenumber" name="L520" href="#L520">520</a>             }
-<a class="jxr_linenumber" name="L521" href="#L521">521</a>         };
-<a class="jxr_linenumber" name="L522" href="#L522">522</a> 
-<a class="jxr_linenumber" name="L523" href="#L523">523</a>         checkNextInRange(max, sampleSize, nextMethod);
-<a class="jxr_linenumber" name="L524" href="#L524">524</a>     }
-<a class="jxr_linenumber" name="L525" href="#L525">525</a> 
-<a class="jxr_linenumber" name="L526" href="#L526">526</a>     <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="L527" href="#L527">527</a> <em class="jxr_javadoccomment">     * Tests uniformity of the distribution produced by {@code nextDouble()}.</em>
-<a class="jxr_linenumber" name="L528" href="#L528">528</a> <em class="jxr_javadoccomment">     *</em>
-<a class="jxr_linenumber" name="L529" href="#L529">529</a> <em class="jxr_javadoccomment">     * @param sampleSize Number of random values generated.</em>
-<a class="jxr_linenumber" name="L530" href="#L530">530</a> <em class="jxr_javadoccomment">     */</em>
-<a class="jxr_linenumber" name="L531" href="#L531">531</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> checkNextDouble(<strong class="jxr_keyword">int</strong> sampleSize) {
-<a class="jxr_linenumber" name="L532" href="#L532">532</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">int</strong> max = 578;
-<a class="jxr_linenumber" name="L533" href="#L533">533</a>         <strong class="jxr_keyword">final</strong> Callable&lt;Integer&gt; nextMethod = <strong class="jxr_keyword">new</strong> Callable&lt;Integer&gt;() {
-<a class="jxr_linenumber" name="L534" href="#L534">534</a>             @Override
-<a class="jxr_linenumber" name="L535" href="#L535">535</a>             <strong class="jxr_keyword">public</strong> Integer call() <strong class="jxr_keyword">throws</strong> Exception {
-<a class="jxr_linenumber" name="L536" href="#L536">536</a>                 <strong class="jxr_keyword">return</strong> (<strong class="jxr_keyword">int</strong>) (max * generator.nextDouble());
-<a class="jxr_linenumber" name="L537" href="#L537">537</a>             }
-<a class="jxr_linenumber" name="L538" href="#L538">538</a>         };
-<a class="jxr_linenumber" name="L539" href="#L539">539</a> 
-<a class="jxr_linenumber" name="L540" href="#L540">540</a>         checkNextInRange(max, sampleSize, nextMethod);
-<a class="jxr_linenumber" name="L541" href="#L541">541</a>     }
-<a class="jxr_linenumber" name="L542" href="#L542">542</a> 
-<a class="jxr_linenumber" name="L543" href="#L543">543</a>     <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="L544" href="#L544">544</a> <em class="jxr_javadoccomment">     * Tests uniformity of the distribution produced by the given</em>
-<a class="jxr_linenumber" name="L545" href="#L545">545</a> <em class="jxr_javadoccomment">     * {@code nextMethod}.</em>
-<a class="jxr_linenumber" name="L546" href="#L546">546</a> <em class="jxr_javadoccomment">     * It performs a chi-square test of homogeneity of the observed</em>
-<a class="jxr_linenumber" name="L547" href="#L547">547</a> <em class="jxr_javadoccomment">     * distribution with the expected uniform distribution.</em>
-<a class="jxr_linenumber" name="L548" href="#L548">548</a> <em class="jxr_javadoccomment">     * Tests are performed at the 1% level and an average failure rate</em>
-<a class="jxr_linenumber" name="L549" href="#L549">549</a> <em class="jxr_javadoccomment">     * higher than 2% (i.e. more than 20 null hypothesis rejections)</em>
-<a class="jxr_linenumber" name="L550" href="#L550">550</a> <em class="jxr_javadoccomment">     * causes the test case to fail.</em>
-<a class="jxr_linenumber" name="L551" href="#L551">551</a> <em class="jxr_javadoccomment">     *</em>
-<a class="jxr_linenumber" name="L552" href="#L552">552</a> <em class="jxr_javadoccomment">     * @param max Upper bound.</em>
-<a class="jxr_linenumber" name="L553" href="#L553">553</a> <em class="jxr_javadoccomment">     * @param nextMethod method to call.</em>
-<a class="jxr_linenumber" name="L554" href="#L554">554</a> <em class="jxr_javadoccomment">     * @param sampleSize Number of random values generated.</em>
-<a class="jxr_linenumber" name="L555" href="#L555">555</a> <em class="jxr_javadoccomment">     */</em>
-<a class="jxr_linenumber" name="L556" href="#L556">556</a>     <strong class="jxr_keyword">private</strong> &lt;T <strong class="jxr_keyword">extends</strong> Number&gt; <strong class="jxr_keyword">void</strong> checkNextInRange(T max,
-<a class="jxr_linenumber" name="L557" href="#L557">557</a>                                                      <strong class="jxr_keyword">int</strong> sampleSize,
-<a class="jxr_linenumber" name="L558" href="#L558">558</a>                                                      Callable&lt;T&gt; nextMethod) {
-<a class="jxr_linenumber" name="L559" href="#L559">559</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">int</strong> numTests = 500;
-<a class="jxr_linenumber" name="L560" href="#L560">560</a> 
-<a class="jxr_linenumber" name="L561" href="#L561">561</a>         <em class="jxr_comment">// Do not change (statistical test assumes that dof = 10).</em>
-<a class="jxr_linenumber" name="L562" href="#L562">562</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">int</strong> numBins = 10;
-<a class="jxr_linenumber" name="L563" href="#L563">563</a> 
-<a class="jxr_linenumber" name="L564" href="#L564">564</a>         <em class="jxr_comment">// Set up bins.</em>
-<a class="jxr_linenumber" name="L565" href="#L565">565</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">long</strong> n = max.longValue();
-<a class="jxr_linenumber" name="L566" href="#L566">566</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">long</strong>[] binUpperBounds = <strong class="jxr_keyword">new</strong> <strong class="jxr_keyword">long</strong>[numBins];
-<a class="jxr_linenumber" name="L567" href="#L567">567</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> step = n / (<strong class="jxr_keyword">double</strong>) numBins;
-<a class="jxr_linenumber" name="L568" href="#L568">568</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> k = 0; k &lt; numBins; k++) {
-<a class="jxr_linenumber" name="L569" href="#L569">569</a>             binUpperBounds[k] = (<strong class="jxr_keyword">long</strong>) ((k + 1) * step);
-<a class="jxr_linenumber" name="L570" href="#L570">570</a>         }
-<a class="jxr_linenumber" name="L571" href="#L571">571</a> 
-<a class="jxr_linenumber" name="L572" href="#L572">572</a>         <em class="jxr_comment">// Run the tests.</em>
-<a class="jxr_linenumber" name="L573" href="#L573">573</a>         <strong class="jxr_keyword">int</strong> numFailures = 0;
-<a class="jxr_linenumber" name="L574" href="#L574">574</a> 
-<a class="jxr_linenumber" name="L575" href="#L575">575</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong>[] expected = <strong class="jxr_keyword">new</strong> <strong class="jxr_keyword">double</strong>[numBins];
-<a class="jxr_linenumber" name="L576" href="#L576">576</a>         <strong class="jxr_keyword">long</strong> previousUpperBound = 0;
-<a class="jxr_linenumber" name="L577" href="#L577">577</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> k = 0; k &lt; numBins; k++) {
-<a class="jxr_linenumber" name="L578" href="#L578">578</a>             <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">long</strong> range = binUpperBounds[k] - previousUpperBound;
-<a class="jxr_linenumber" name="L579" href="#L579">579</a>             expected[k] = sampleSize * (range / (<strong class="jxr_keyword">double</strong>) n);
-<a class="jxr_linenumber" name="L580" href="#L580">580</a>             previousUpperBound = binUpperBounds[k];
-<a class="jxr_linenumber" name="L581" href="#L581">581</a>         }
-<a class="jxr_linenumber" name="L582" href="#L582">582</a> 
-<a class="jxr_linenumber" name="L583" href="#L583">583</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">int</strong>[] observed = <strong class="jxr_keyword">new</strong> <strong class="jxr_keyword">int</strong>[numBins];
-<a class="jxr_linenumber" name="L584" href="#L584">584</a>         <em class="jxr_comment">// Chi-square critical value with 10 degrees of freedom</em>
-<a class="jxr_linenumber" name="L585" href="#L585">585</a>         <em class="jxr_comment">// and 1% significance level.</em>
-<a class="jxr_linenumber" name="L586" href="#L586">586</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> chi2CriticalValue = 23.209;
-<a class="jxr_linenumber" name="L587" href="#L587">587</a> 
-<a class="jxr_linenumber" name="L588" href="#L588">588</a>         <strong class="jxr_keyword">try</strong> {
-<a class="jxr_linenumber" name="L589" href="#L589">589</a>             <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; numTests; i++) {
-<a class="jxr_linenumber" name="L590" href="#L590">590</a>                 Arrays.fill(observed, 0);
-<a class="jxr_linenumber" name="L591" href="#L591">591</a>                 <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> j = 0; j &lt; sampleSize; j++) {
-<a class="jxr_linenumber" name="L592" href="#L592">592</a>                     <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">long</strong> value = nextMethod.call().longValue();
-<a class="jxr_linenumber" name="L593" href="#L593">593</a>                     Assert.assertTrue(<span class="jxr_string">"Range"</span>, (value &gt;= 0) &amp;&amp; (value &lt; n));
-<a class="jxr_linenumber" name="L594" href="#L594">594</a> 
-<a class="jxr_linenumber" name="L595" href="#L595">595</a>                     <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> k = 0; k &lt; numBins; k++) {
-<a class="jxr_linenumber" name="L596" href="#L596">596</a>                         <strong class="jxr_keyword">if</strong> (value &lt; binUpperBounds[k]) {
-<a class="jxr_linenumber" name="L597" href="#L597">597</a>                             ++observed[k];
-<a class="jxr_linenumber" name="L598" href="#L598">598</a>                             <strong class="jxr_keyword">break</strong>;
-<a class="jxr_linenumber" name="L599" href="#L599">599</a>                         }
-<a class="jxr_linenumber" name="L600" href="#L600">600</a>                     }
-<a class="jxr_linenumber" name="L601" href="#L601">601</a>                 }
-<a class="jxr_linenumber" name="L602" href="#L602">602</a> 
-<a class="jxr_linenumber" name="L603" href="#L603">603</a>                 <em class="jxr_comment">// Compute chi-square.</em>
-<a class="jxr_linenumber" name="L604" href="#L604">604</a>                 <strong class="jxr_keyword">double</strong> chi2 = 0;
-<a class="jxr_linenumber" name="L605" href="#L605">605</a>                 <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> k = 0; k &lt; numBins; k++) {
-<a class="jxr_linenumber" name="L606" href="#L606">606</a>                     <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> diff = observed[k] - expected[k];
-<a class="jxr_linenumber" name="L607" href="#L607">607</a>                     chi2 += diff * diff / expected[k];
-<a class="jxr_linenumber" name="L608" href="#L608">608</a>                 }
-<a class="jxr_linenumber" name="L609" href="#L609">609</a> 
-<a class="jxr_linenumber" name="L610" href="#L610">610</a>                 <em class="jxr_comment">// Statistics check.</em>
-<a class="jxr_linenumber" name="L611" href="#L611">611</a>                 <strong class="jxr_keyword">if</strong> (chi2 &gt; chi2CriticalValue) {
-<a class="jxr_linenumber" name="L612" href="#L612">612</a>                     ++numFailures;
-<a class="jxr_linenumber" name="L613" href="#L613">613</a>                 }
-<a class="jxr_linenumber" name="L614" href="#L614">614</a>             }
-<a class="jxr_linenumber" name="L615" href="#L615">615</a>         } <strong class="jxr_keyword">catch</strong> (Exception e) {
-<a class="jxr_linenumber" name="L616" href="#L616">616</a>             <em class="jxr_comment">// Should never happen.</em>
-<a class="jxr_linenumber" name="L617" href="#L617">617</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> RuntimeException(<span class="jxr_string">"Unexpected"</span>, e);
-<a class="jxr_linenumber" name="L618" href="#L618">618</a>         }
+<a class="jxr_linenumber" name="L333" href="#L333">333</a>     @Test(expected=IllegalArgumentException.<strong class="jxr_keyword">class</strong>)
+<a class="jxr_linenumber" name="L334" href="#L334">334</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> testStateWrongSize() {
+<a class="jxr_linenumber" name="L335" href="#L335">335</a>         <em class="jxr_comment">// We don't know what is the state of "java.lang.Random": skipping.</em>
+<a class="jxr_linenumber" name="L336" href="#L336">336</a>         Assume.assumeTrue(generator.toString().indexOf(<span class="jxr_string">"JDKRandom"</span>) == -1);
+<a class="jxr_linenumber" name="L337" href="#L337">337</a> 
+<a class="jxr_linenumber" name="L338" href="#L338">338</a>         <strong class="jxr_keyword">final</strong> RandomSource.State state = RandomSource.saveState(<strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/commons/rng/ProvidersCommonParametricTest.html">DummyGenerator</a>());
+<a class="jxr_linenumber" name="L339" href="#L339">339</a>         <em class="jxr_comment">// Try to restore with an invalid state (wrong size).</em>
+<a class="jxr_linenumber" name="L340" href="#L340">340</a>         RandomSource.restoreState(generator, state);
+<a class="jxr_linenumber" name="L341" href="#L341">341</a>     }
+<a class="jxr_linenumber" name="L342" href="#L342">342</a> 
+<a class="jxr_linenumber" name="L343" href="#L343">343</a>     <em class="jxr_comment">///// Support methods below.</em>
+<a class="jxr_linenumber" name="L344" href="#L344">344</a> 
+<a class="jxr_linenumber" name="L345" href="#L345">345</a>     <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="L346" href="#L346">346</a> <em class="jxr_javadoccomment">     * Populates a list with random numbers.</em>
+<a class="jxr_linenumber" name="L347" href="#L347">347</a> <em class="jxr_javadoccomment">     *</em>
+<a class="jxr_linenumber" name="L348" href="#L348">348</a> <em class="jxr_javadoccomment">     * @param n Loop counter.</em>
+<a class="jxr_linenumber" name="L349" href="#L349">349</a> <em class="jxr_javadoccomment">     * @return a list containing {@code 11 * n} random numbers.</em>
+<a class="jxr_linenumber" name="L350" href="#L350">350</a> <em class="jxr_javadoccomment">     */</em>
+<a class="jxr_linenumber" name="L351" href="#L351">351</a>     <strong class="jxr_keyword">private</strong> List&lt;Number&gt; makeList(<strong class="jxr_keyword">int</strong> n) {
+<a class="jxr_linenumber" name="L352" href="#L352">352</a>         <strong class="jxr_keyword">final</strong> List&lt;Number&gt; list = <strong class="jxr_keyword">new</strong> ArrayList&lt;Number&gt;();
+<a class="jxr_linenumber" name="L353" href="#L353">353</a> 
+<a class="jxr_linenumber" name="L354" href="#L354">354</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; n; i++) {
+<a class="jxr_linenumber" name="L355" href="#L355">355</a>             <em class="jxr_comment">// Append 11 values.</em>
+<a class="jxr_linenumber" name="L356" href="#L356">356</a>             list.add(generator.nextInt());
+<a class="jxr_linenumber" name="L357" href="#L357">357</a>             list.add(generator.nextInt(21));
+<a class="jxr_linenumber" name="L358" href="#L358">358</a>             list.add(generator.nextInt(436));
+<a class="jxr_linenumber" name="L359" href="#L359">359</a>             list.add(generator.nextLong());
+<a class="jxr_linenumber" name="L360" href="#L360">360</a>             list.add(generator.nextLong(157894));
+<a class="jxr_linenumber" name="L361" href="#L361">361</a>             list.add(generator.nextLong(5745833));
+<a class="jxr_linenumber" name="L362" href="#L362">362</a>             list.add(generator.nextFloat());
+<a class="jxr_linenumber" name="L363" href="#L363">363</a>             list.add(generator.nextFloat());
+<a class="jxr_linenumber" name="L364" href="#L364">364</a>             list.add(generator.nextDouble());
+<a class="jxr_linenumber" name="L365" href="#L365">365</a>             list.add(generator.nextDouble());
+<a class="jxr_linenumber" name="L366" href="#L366">366</a>             list.add(generator.nextDouble());
+<a class="jxr_linenumber" name="L367" href="#L367">367</a>         }
+<a class="jxr_linenumber" name="L368" href="#L368">368</a> 
+<a class="jxr_linenumber" name="L369" href="#L369">369</a>         <strong class="jxr_keyword">return</strong> list;
+<a class="jxr_linenumber" name="L370" href="#L370">370</a>     }
+<a class="jxr_linenumber" name="L371" href="#L371">371</a> 
+<a class="jxr_linenumber" name="L372" href="#L372">372</a>     <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="L373" href="#L373">373</a> <em class="jxr_javadoccomment">     * Checks that the generator values can be placed into 256 bins with</em>
+<a class="jxr_linenumber" name="L374" href="#L374">374</a> <em class="jxr_javadoccomment">     * approximately equal number of counts.</em>
+<a class="jxr_linenumber" name="L375" href="#L375">375</a> <em class="jxr_javadoccomment">     * Test allows to select only part of the buffer for performing the</em>
+<a class="jxr_linenumber" name="L376" href="#L376">376</a> <em class="jxr_javadoccomment">     * statistics.</em>
+<a class="jxr_linenumber" name="L377" href="#L377">377</a> <em class="jxr_javadoccomment">     *</em>
+<a class="jxr_linenumber" name="L378" href="#L378">378</a> <em class="jxr_javadoccomment">     * @param buffer Buffer to be filled.</em>
+<a class="jxr_linenumber" name="L379" href="#L379">379</a> <em class="jxr_javadoccomment">     * @param first First element (included) of {@code buffer} range for</em>
+<a class="jxr_linenumber" name="L380" href="#L380">380</a> <em class="jxr_javadoccomment">     * which statistics must be taken into account.</em>
+<a class="jxr_linenumber" name="L381" href="#L381">381</a> <em class="jxr_javadoccomment">     * @param last Last element (excluded) of {@code buffer} range for</em>
+<a class="jxr_linenumber" name="L382" href="#L382">382</a> <em class="jxr_javadoccomment">     * which statistics must be taken into account.</em>
+<a class="jxr_linenumber" name="L383" href="#L383">383</a> <em class="jxr_javadoccomment">     * @param nextMethod Method that fills the given {@code buffer}.</em>
+<a class="jxr_linenumber" name="L384" href="#L384">384</a> <em class="jxr_javadoccomment">     * @return {@code true} if the distribution is uniform.</em>
+<a class="jxr_linenumber" name="L385" href="#L385">385</a> <em class="jxr_javadoccomment">     */</em>
+<a class="jxr_linenumber" name="L386" href="#L386">386</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">boolean</strong> isUniformNextBytes(byte[] buffer,
+<a class="jxr_linenumber" name="L387" href="#L387">387</a>                                        <strong class="jxr_keyword">int</strong> first,
+<a class="jxr_linenumber" name="L388" href="#L388">388</a>                                        <strong class="jxr_keyword">int</strong> last,
+<a class="jxr_linenumber" name="L389" href="#L389">389</a>                                        Runnable nextMethod) {
+<a class="jxr_linenumber" name="L390" href="#L390">390</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">int</strong> sampleSize = 10000;
+<a class="jxr_linenumber" name="L391" href="#L391">391</a> 
+<a class="jxr_linenumber" name="L392" href="#L392">392</a>         <em class="jxr_comment">// Number of possible values (do not change).</em>
+<a class="jxr_linenumber" name="L393" href="#L393">393</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">int</strong> byteRange = 256;
+<a class="jxr_linenumber" name="L394" href="#L394">394</a>         <em class="jxr_comment">// Chi-square critical value with 256 degrees of freedom</em>
+<a class="jxr_linenumber" name="L395" href="#L395">395</a>         <em class="jxr_comment">// and 1% significance level.</em>
+<a class="jxr_linenumber" name="L396" href="#L396">396</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> chi2CriticalValue = 311.560343;
+<a class="jxr_linenumber" name="L397" href="#L397">397</a>         <em class="jxr_comment">// To transform a byte value into its bin index.</em>
+<a class="jxr_linenumber" name="L398" href="#L398">398</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">int</strong> byteRangeOffset = 128;
+<a class="jxr_linenumber" name="L399" href="#L399">399</a> 
+<a class="jxr_linenumber" name="L400" href="#L400">400</a>         <em class="jxr_comment">// Bins.</em>
+<a class="jxr_linenumber" name="L401" href="#L401">401</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">long</strong>[] observed = <strong class="jxr_keyword">new</strong> <strong class="jxr_keyword">long</strong>[byteRange];
+<a class="jxr_linenumber" name="L402" href="#L402">402</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong>[] expected = <strong class="jxr_keyword">new</strong> <strong class="jxr_keyword">double</strong>[byteRange];
+<a class="jxr_linenumber" name="L403" href="#L403">403</a> 
+<a class="jxr_linenumber" name="L404" href="#L404">404</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; byteRange; i++) {
+<a class="jxr_linenumber" name="L405" href="#L405">405</a>             expected[i] = sampleSize * (last - first) / (<strong class="jxr_keyword">double</strong>) byteRange;
+<a class="jxr_linenumber" name="L406" href="#L406">406</a>         }
+<a class="jxr_linenumber" name="L407" href="#L407">407</a> 
+<a class="jxr_linenumber" name="L408" href="#L408">408</a>         <strong class="jxr_keyword">try</strong> {
+<a class="jxr_linenumber" name="L409" href="#L409">409</a>             <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> k = 0; k &lt; sampleSize; k++) {
+<a class="jxr_linenumber" name="L410" href="#L410">410</a>                 nextMethod.run();
+<a class="jxr_linenumber" name="L411" href="#L411">411</a> 
+<a class="jxr_linenumber" name="L412" href="#L412">412</a>                 <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = first; i &lt; last; i++) {
+<a class="jxr_linenumber" name="L413" href="#L413">413</a>                     <strong class="jxr_keyword">final</strong> byte b = buffer[i];
+<a class="jxr_linenumber" name="L414" href="#L414">414</a>                     ++observed[b + byteRangeOffset];
+<a class="jxr_linenumber" name="L415" href="#L415">415</a>                 }
+<a class="jxr_linenumber" name="L416" href="#L416">416</a>             }
+<a class="jxr_linenumber" name="L417" href="#L417">417</a>         } <strong class="jxr_keyword">catch</strong> (Exception e) {
+<a class="jxr_linenumber" name="L418" href="#L418">418</a>             <em class="jxr_comment">// Should never happen.</em>
+<a class="jxr_linenumber" name="L419" href="#L419">419</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> RuntimeException(<span class="jxr_string">"Unexpected"</span>);
+<a class="jxr_linenumber" name="L420" href="#L420">420</a>         }
+<a class="jxr_linenumber" name="L421" href="#L421">421</a> 
+<a class="jxr_linenumber" name="L422" href="#L422">422</a>         <em class="jxr_comment">// Compute chi-square.</em>
+<a class="jxr_linenumber" name="L423" href="#L423">423</a>         <strong class="jxr_keyword">double</strong> chi2 = 0;
+<a class="jxr_linenumber" name="L424" href="#L424">424</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> k = 0; k &lt; byteRange; k++) {
+<a class="jxr_linenumber" name="L425" href="#L425">425</a>             <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> diff = observed[k] - expected[k];
+<a class="jxr_linenumber" name="L426" href="#L426">426</a>             chi2 += diff * diff / expected[k];
+<a class="jxr_linenumber" name="L427" href="#L427">427</a>         }
+<a class="jxr_linenumber" name="L428" href="#L428">428</a> 
+<a class="jxr_linenumber" name="L429" href="#L429">429</a>         <em class="jxr_comment">// Statistics check.</em>
+<a class="jxr_linenumber" name="L430" href="#L430">430</a>         <strong class="jxr_keyword">return</strong> chi2 &lt; chi2CriticalValue;
+<a class="jxr_linenumber" name="L431" href="#L431">431</a>     }
+<a class="jxr_linenumber" name="L432" href="#L432">432</a> 
+<a class="jxr_linenumber" name="L433" href="#L433">433</a>     <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="L434" href="#L434">434</a> <em class="jxr_javadoccomment">     * Checks that the generator values can be placed into 2 bins with</em>
+<a class="jxr_linenumber" name="L435" href="#L435">435</a> <em class="jxr_javadoccomment">     * approximately equal number of counts.</em>
+<a class="jxr_linenumber" name="L436" href="#L436">436</a> <em class="jxr_javadoccomment">     * The test uses the expectation from a fixed-step "random walk".</em>
+<a class="jxr_linenumber" name="L437" href="#L437">437</a> <em class="jxr_javadoccomment">     *</em>
+<a class="jxr_linenumber" name="L438" href="#L438">438</a> <em class="jxr_javadoccomment">     * @param nextMethod Method that returns {@code true} if the generated</em>
+<a class="jxr_linenumber" name="L439" href="#L439">439</a> <em class="jxr_javadoccomment">     * values are to be placed in the first bin, {@code false} if it must</em>
+<a class="jxr_linenumber" name="L440" href="#L440">440</a> <em class="jxr_javadoccomment">     * go to the second bin.</em>
+<a class="jxr_linenumber" name="L441" href="#L441">441</a> <em class="jxr_javadoccomment">     */</em>
+<a class="jxr_linenumber" name="L442" href="#L442">442</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> checkRandomWalk(<strong class="jxr_keyword">int</strong> sampleSize,
+<a class="jxr_linenumber" name="L443" href="#L443">443</a>                                  Callable&lt;Boolean&gt; nextMethod) {
+<a class="jxr_linenumber" name="L444" href="#L444">444</a>         <strong class="jxr_keyword">int</strong> walk = 0;
+<a class="jxr_linenumber" name="L445" href="#L445">445</a> 
+<a class="jxr_linenumber" name="L446" href="#L446">446</a>         <strong class="jxr_keyword">try</strong> {
+<a class="jxr_linenumber" name="L447" href="#L447">447</a>             <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> k = 0; k &lt; sampleSize; ++k) {
+<a class="jxr_linenumber" name="L448" href="#L448">448</a>                 <strong class="jxr_keyword">if</strong> (nextMethod.call()) {
+<a class="jxr_linenumber" name="L449" href="#L449">449</a>                     ++walk;
+<a class="jxr_linenumber" name="L450" href="#L450">450</a>                 } <strong class="jxr_keyword">else</strong> {
+<a class="jxr_linenumber" name="L451" href="#L451">451</a>                     --walk;
+<a class="jxr_linenumber" name="L452" href="#L452">452</a>                 }
+<a class="jxr_linenumber" name="L453" href="#L453">453</a>             }
+<a class="jxr_linenumber" name="L454" href="#L454">454</a>         } <strong class="jxr_keyword">catch</strong> (Exception e) {
+<a class="jxr_linenumber" name="L455" href="#L455">455</a>             <em class="jxr_comment">// Should never happen.</em>
+<a class="jxr_linenumber" name="L456" href="#L456">456</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> RuntimeException(<span class="jxr_string">"Unexpected"</span>);
+<a class="jxr_linenumber" name="L457" href="#L457">457</a>         }
+<a class="jxr_linenumber" name="L458" href="#L458">458</a> 
+<a class="jxr_linenumber" name="L459" href="#L459">459</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> actual = Math.abs(walk);
+<a class="jxr_linenumber" name="L460" href="#L460">460</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> max = Math.sqrt(sampleSize) * 2.576;
+<a class="jxr_linenumber" name="L461" href="#L461">461</a>         Assert.assertTrue(generator + <span class="jxr_string">": Walked too far astray: "</span> + actual +
+<a class="jxr_linenumber" name="L462" href="#L462">462</a>                           <span class="jxr_string">" &gt; "</span> + max +
+<a class="jxr_linenumber" name="L463" href="#L463">463</a>                           <span class="jxr_string">" (test will fail randomly about 1 in 100 times)"</span>,
+<a class="jxr_linenumber" name="L464" href="#L464">464</a>                           actual &lt; max);
+<a class="jxr_linenumber" name="L465" href="#L465">465</a>     }
+<a class="jxr_linenumber" name="L466" href="#L466">466</a> 
+<a class="jxr_linenumber" name="L467" href="#L467">467</a>     <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="L468" href="#L468">468</a> <em class="jxr_javadoccomment">     * Tests uniformity of the distribution produced by {@code nextInt(int)}.</em>
+<a class="jxr_linenumber" name="L469" href="#L469">469</a> <em class="jxr_javadoccomment">     *</em>
+<a class="jxr_linenumber" name="L470" href="#L470">470</a> <em class="jxr_javadoccomment">     * @param max Upper bound.</em>
+<a class="jxr_linenumber" name="L471" href="#L471">471</a> <em class="jxr_javadoccomment">     * @param sampleSize Number of random values generated.</em>
+<a class="jxr_linenumber" name="L472" href="#L472">472</a> <em class="jxr_javadoccomment">     */</em>
+<a class="jxr_linenumber" name="L473" href="#L473">473</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> checkNextIntegerInRange(<strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">int</strong> max,
+<a class="jxr_linenumber" name="L474" href="#L474">474</a>                                          <strong class="jxr_keyword">int</strong> sampleSize) {
+<a class="jxr_linenumber" name="L475" href="#L475">475</a>         <strong class="jxr_keyword">final</strong> Callable&lt;Integer&gt; nextMethod = <strong class="jxr_keyword">new</strong> Callable&lt;Integer&gt;() {
+<a class="jxr_linenumber" name="L476" href="#L476">476</a>             @Override
+<a class="jxr_linenumber" name="L477" href="#L477">477</a>             <strong class="jxr_keyword">public</strong> Integer call() <strong class="jxr_keyword">throws</strong> Exception {
+<a class="jxr_linenumber" name="L478" href="#L478">478</a>                 <strong class="jxr_keyword">return</strong> generator.nextInt(max);
+<a class="jxr_linenumber" name="L479" href="#L479">479</a>             }
+<a class="jxr_linenumber" name="L480" href="#L480">480</a>         };
+<a class="jxr_linenumber" name="L481" href="#L481">481</a> 
+<a class="jxr_linenumber" name="L482" href="#L482">482</a>         checkNextInRange(max, sampleSize, nextMethod);
+<a class="jxr_linenumber" name="L483" href="#L483">483</a>     }
+<a class="jxr_linenumber" name="L484" href="#L484">484</a> 
+<a class="jxr_linenumber" name="L485" href="#L485">485</a>     <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="L486" href="#L486">486</a> <em class="jxr_javadoccomment">     * Tests uniformity of the distribution produced by {@code nextLong(long)}.</em>
+<a class="jxr_linenumber" name="L487" href="#L487">487</a> <em class="jxr_javadoccomment">     *</em>
+<a class="jxr_linenumber" name="L488" href="#L488">488</a> <em class="jxr_javadoccomment">     * @param max Upper bound.</em>
+<a class="jxr_linenumber" name="L489" href="#L489">489</a> <em class="jxr_javadoccomment">     * @param sampleSize Number of random values generated.</em>
+<a class="jxr_linenumber" name="L490" href="#L490">490</a> <em class="jxr_javadoccomment">     */</em>
+<a class="jxr_linenumber" name="L491" href="#L491">491</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> checkNextLongInRange(<strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">long</strong> max,
+<a class="jxr_linenumber" name="L492" href="#L492">492</a>                                       <strong class="jxr_keyword">int</strong> sampleSize) {
+<a class="jxr_linenumber" name="L493" href="#L493">493</a>         <strong class="jxr_keyword">final</strong> Callable&lt;Long&gt; nextMethod = <strong class="jxr_keyword">new</strong> Callable&lt;Long&gt;() {
+<a class="jxr_linenumber" name="L494" href="#L494">494</a>             @Override
+<a class="jxr_linenumber" name="L495" href="#L495">495</a>             <strong class="jxr_keyword">public</strong> Long call() <strong class="jxr_keyword">throws</strong> Exception {
+<a class="jxr_linenumber" name="L496" href="#L496">496</a>                 <strong class="jxr_keyword">return</strong> generator.nextLong(max);
+<a class="jxr_linenumber" name="L497" href="#L497">497</a>             }
+<a class="jxr_linenumber" name="L498" href="#L498">498</a>         };
+<a class="jxr_linenumber" name="L499" href="#L499">499</a> 
+<a class="jxr_linenumber" name="L500" href="#L500">500</a>         checkNextInRange(max, sampleSize, nextMethod);
+<a class="jxr_linenumber" name="L501" href="#L501">501</a>     }
+<a class="jxr_linenumber" name="L502" href="#L502">502</a> 
+<a class="jxr_linenumber" name="L503" href="#L503">503</a>     <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="L504" href="#L504">504</a> <em class="jxr_javadoccomment">     * Tests uniformity of the distribution produced by {@code nextFloat()}.</em>
+<a class="jxr_linenumber" name="L505" href="#L505">505</a> <em class="jxr_javadoccomment">     *</em>
+<a class="jxr_linenumber" name="L506" href="#L506">506</a> <em class="jxr_javadoccomment">     * @param sampleSize Number of random values generated.</em>
+<a class="jxr_linenumber" name="L507" href="#L507">507</a> <em class="jxr_javadoccomment">     */</em>
+<a class="jxr_linenumber" name="L508" href="#L508">508</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> checkNextFloat(<strong class="jxr_keyword">int</strong> sampleSize) {
+<a class="jxr_linenumber" name="L509" href="#L509">509</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">int</strong> max = 1234;
+<a class="jxr_linenumber" name="L510" href="#L510">510</a>         <strong class="jxr_keyword">final</strong> Callable&lt;Integer&gt; nextMethod = <strong class="jxr_keyword">new</strong> Callable&lt;Integer&gt;() {
+<a class="jxr_linenumber" name="L511" href="#L511">511</a>             @Override
+<a class="jxr_linenumber" name="L512" href="#L512">512</a>             <strong class="jxr_keyword">public</strong> Integer call() <strong class="jxr_keyword">throws</strong> Exception {
+<a class="jxr_linenumber" name="L513" href="#L513">513</a>                 <strong class="jxr_keyword">return</strong> (<strong class="jxr_keyword">int</strong>) (max * generator.nextFloat());
+<a class="jxr_linenumber" name="L514" href="#L514">514</a>             }
+<a class="jxr_linenumber" name="L515" href="#L515">515</a>         };
+<a class="jxr_linenumber" name="L516" href="#L516">516</a> 
+<a class="jxr_linenumber" name="L517" href="#L517">517</a>         checkNextInRange(max, sampleSize, nextMethod);
+<a class="jxr_linenumber" name="L518" href="#L518">518</a>     }
+<a class="jxr_linenumber" name="L519" href="#L519">519</a> 
+<a class="jxr_linenumber" name="L520" href="#L520">520</a>     <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="L521" href="#L521">521</a> <em class="jxr_javadoccomment">     * Tests uniformity of the distribution produced by {@code nextDouble()}.</em>
+<a class="jxr_linenumber" name="L522" href="#L522">522</a> <em class="jxr_javadoccomment">     *</em>
+<a class="jxr_linenumber" name="L523" href="#L523">523</a> <em class="jxr_javadoccomment">     * @param sampleSize Number of random values generated.</em>
+<a class="jxr_linenumber" name="L524" href="#L524">524</a> <em class="jxr_javadoccomment">     */</em>
+<a class="jxr_linenumber" name="L525" href="#L525">525</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> checkNextDouble(<strong class="jxr_keyword">int</strong> sampleSize) {
+<a class="jxr_linenumber" name="L526" href="#L526">526</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">int</strong> max = 578;
+<a class="jxr_linenumber" name="L527" href="#L527">527</a>         <strong class="jxr_keyword">final</strong> Callable&lt;Integer&gt; nextMethod = <strong class="jxr_keyword">new</strong> Callable&lt;Integer&gt;() {
+<a class="jxr_linenumber" name="L528" href="#L528">528</a>             @Override
+<a class="jxr_linenumber" name="L529" href="#L529">529</a>             <strong class="jxr_keyword">public</strong> Integer call() <strong class="jxr_keyword">throws</strong> Exception {
+<a class="jxr_linenumber" name="L530" href="#L530">530</a>                 <strong class="jxr_keyword">return</strong> (<strong class="jxr_keyword">int</strong>) (max * generator.nextDouble());
+<a class="jxr_linenumber" name="L531" href="#L531">531</a>             }
+<a class="jxr_linenumber" name="L532" href="#L532">532</a>         };
+<a class="jxr_linenumber" name="L533" href="#L533">533</a> 
+<a class="jxr_linenumber" name="L534" href="#L534">534</a>         checkNextInRange(max, sampleSize, nextMethod);
+<a class="jxr_linenumber" name="L535" href="#L535">535</a>     }
+<a class="jxr_linenumber" name="L536" href="#L536">536</a> 
+<a class="jxr_linenumber" name="L537" href="#L537">537</a>     <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="L538" href="#L538">538</a> <em class="jxr_javadoccomment">     * Tests uniformity of the distribution produced by the given</em>
+<a class="jxr_linenumber" name="L539" href="#L539">539</a> <em class="jxr_javadoccomment">     * {@code nextMethod}.</em>
+<a class="jxr_linenumber" name="L540" href="#L540">540</a> <em class="jxr_javadoccomment">     * It performs a chi-square test of homogeneity of the observed</em>
+<a class="jxr_linenumber" name="L541" href="#L541">541</a> <em class="jxr_javadoccomment">     * distribution with the expected uniform distribution.</em>
+<a class="jxr_linenumber" name="L542" href="#L542">542</a> <em class="jxr_javadoccomment">     * Tests are performed at the 1% level and an average failure rate</em>
+<a class="jxr_linenumber" name="L543" href="#L543">543</a> <em class="jxr_javadoccomment">     * higher than 2% (i.e. more than 20 null hypothesis rejections)</em>
+<a class="jxr_linenumber" name="L544" href="#L544">544</a> <em class="jxr_javadoccomment">     * causes the test case to fail.</em>
+<a class="jxr_linenumber" name="L545" href="#L545">545</a> <em class="jxr_javadoccomment">     *</em>
+<a class="jxr_linenumber" name="L546" href="#L546">546</a> <em class="jxr_javadoccomment">     * @param max Upper bound.</em>
+<a class="jxr_linenumber" name="L547" href="#L547">547</a> <em class="jxr_javadoccomment">     * @param nextMethod method to call.</em>
+<a class="jxr_linenumber" name="L548" href="#L548">548</a> <em class="jxr_javadoccomment">     * @param sampleSize Number of random values generated.</em>
+<a class="jxr_linenumber" name="L549" href="#L549">549</a> <em class="jxr_javadoccomment">     */</em>
+<a class="jxr_linenumber" name="L550" href="#L550">550</a>     <strong class="jxr_keyword">private</strong> &lt;T <strong class="jxr_keyword">extends</strong> Number&gt; <strong class="jxr_keyword">void</strong> checkNextInRange(T max,
+<a class="jxr_linenumber" name="L551" href="#L551">551</a>                                                      <strong class="jxr_keyword">int</strong> sampleSize,
+<a class="jxr_linenumber" name="L552" href="#L552">552</a>                                                      Callable&lt;T&gt; nextMethod) {
+<a class="jxr_linenumber" name="L553" href="#L553">553</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">int</strong> numTests = 500;
+<a class="jxr_linenumber" name="L554" href="#L554">554</a> 
+<a class="jxr_linenumber" name="L555" href="#L555">555</a>         <em class="jxr_comment">// Do not change (statistical test assumes that dof = 10).</em>
+<a class="jxr_linenumber" name="L556" href="#L556">556</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">int</strong> numBins = 10;
+<a class="jxr_linenumber" name="L557" href="#L557">557</a> 
+<a class="jxr_linenumber" name="L558" href="#L558">558</a>         <em class="jxr_comment">// Set up bins.</em>
+<a class="jxr_linenumber" name="L559" href="#L559">559</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">long</strong> n = max.longValue();
+<a class="jxr_linenumber" name="L560" href="#L560">560</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">long</strong>[] binUpperBounds = <strong class="jxr_keyword">new</strong> <strong class="jxr_keyword">long</strong>[numBins];
+<a class="jxr_linenumber" name="L561" href="#L561">561</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> step = n / (<strong class="jxr_keyword">double</strong>) numBins;
+<a class="jxr_linenumber" name="L562" href="#L562">562</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> k = 0; k &lt; numBins; k++) {
+<a class="jxr_linenumber" name="L563" href="#L563">563</a>             binUpperBounds[k] = (<strong class="jxr_keyword">long</strong>) ((k + 1) * step);
+<a class="jxr_linenumber" name="L564" href="#L564">564</a>         }
+<a class="jxr_linenumber" name="L565" href="#L565">565</a> 
+<a class="jxr_linenumber" name="L566" href="#L566">566</a>         <em class="jxr_comment">// Run the tests.</em>
+<a class="jxr_linenumber" name="L567" href="#L567">567</a>         <strong class="jxr_keyword">int</strong> numFailures = 0;
+<a class="jxr_linenumber" name="L568" href="#L568">568</a> 
+<a class="jxr_linenumber" name="L569" href="#L569">569</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong>[] expected = <strong class="jxr_keyword">new</strong> <strong class="jxr_keyword">double</strong>[numBins];
+<a class="jxr_linenumber" name="L570" href="#L570">570</a>         <strong class="jxr_keyword">long</strong> previousUpperBound = 0;
+<a class="jxr_linenumber" name="L571" href="#L571">571</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> k = 0; k &lt; numBins; k++) {
+<a class="jxr_linenumber" name="L572" href="#L572">572</a>             <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">long</strong> range = binUpperBounds[k] - previousUpperBound;
+<a class="jxr_linenumber" name="L573" href="#L573">573</a>             expected[k] = sampleSize * (range / (<strong class="jxr_keyword">double</strong>) n);
+<a class="jxr_linenumber" name="L574" href="#L574">574</a>             previousUpperBound = binUpperBounds[k];
+<a class="jxr_linenumber" name="L575" href="#L575">575</a>         }
+<a class="jxr_linenumber" name="L576" href="#L576">576</a> 
+<a class="jxr_linenumber" name="L577" href="#L577">577</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">int</strong>[] observed = <strong class="jxr_keyword">new</strong> <strong class="jxr_keyword">int</strong>[numBins];
+<a class="jxr_linenumber" name="L578" href="#L578">578</a>         <em class="jxr_comment">// Chi-square critical value with 10 degrees of freedom</em>
+<a class="jxr_linenumber" name="L579" href="#L579">579</a>         <em class="jxr_comment">// and 1% significance level.</em>
+<a class="jxr_linenumber" name="L580" href="#L580">580</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> chi2CriticalValue = 23.209;
+<a class="jxr_linenumber" name="L581" href="#L581">581</a> 
+<a class="jxr_linenumber" name="L582" href="#L582">582</a>         <strong class="jxr_keyword">try</strong> {
+<a class="jxr_linenumber" name="L583" href="#L583">583</a>             <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; numTests; i++) {
+<a class="jxr_linenumber" name="L584" href="#L584">584</a>                 Arrays.fill(observed, 0);
+<a class="jxr_linenumber" name="L585" href="#L585">585</a>                 <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> j = 0; j &lt; sampleSize; j++) {
+<a class="jxr_linenumber" name="L586" href="#L586">586</a>                     <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">long</strong> value = nextMethod.call().longValue();
+<a class="jxr_linenumber" name="L587" href="#L587">587</a>                     Assert.assertTrue(<span class="jxr_string">"Range"</span>, (value &gt;= 0) &amp;&amp; (value &lt; n));
+<a class="jxr_linenumber" name="L588" href="#L588">588</a> 
+<a class="jxr_linenumber" name="L589" href="#L589">589</a>                     <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> k = 0; k &lt; numBins; k++) {
+<a class="jxr_linenumber" name="L590" href="#L590">590</a>                         <strong class="jxr_keyword">if</strong> (value &lt; binUpperBounds[k]) {
+<a class="jxr_linenumber" name="L591" href="#L591">591</a>                             ++observed[k];
+<a class="jxr_linenumber" name="L592" href="#L592">592</a>                             <strong class="jxr_keyword">break</strong>;
+<a class="jxr_linenumber" name="L593" href="#L593">593</a>                         }
+<a class="jxr_linenumber" name="L594" href="#L594">594</a>                     }
+<a class="jxr_linenumber" name="L595" href="#L595">595</a>                 }
+<a class="jxr_linenumber" name="L596" href="#L596">596</a> 
+<a class="jxr_linenumber" name="L597" href="#L597">597</a>                 <em class="jxr_comment">// Compute chi-square.</em>
+<a class="jxr_linenumber" name="L598" href="#L598">598</a>                 <strong class="jxr_keyword">double</strong> chi2 = 0;
+<a class="jxr_linenumber" name="L599" href="#L599">599</a>                 <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> k = 0; k &lt; numBins; k++) {
+<a class="jxr_linenumber" name="L600" href="#L600">600</a>                     <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> diff = observed[k] - expected[k];
+<a class="jxr_linenumber" name="L601" href="#L601">601</a>                     chi2 += diff * diff / expected[k];
+<a class="jxr_linenumber" name="L602" href="#L602">602</a>                 }
+<a class="jxr_linenumber" name="L603" href="#L603">603</a> 
+<a class="jxr_linenumber" name="L604" href="#L604">604</a>                 <em class="jxr_comment">// Statistics check.</em>
+<a class="jxr_linenumber" name="L605" href="#L605">605</a>                 <strong class="jxr_keyword">if</strong> (chi2 &gt; chi2CriticalValue) {
+<a class="jxr_linenumber" name="L606" href="#L606">606</a>                     ++numFailures;
+<a class="jxr_linenumber" name="L607" href="#L607">607</a>                 }
+<a class="jxr_linenumber" name="L608" href="#L608">608</a>             }
+<a class="jxr_linenumber" name="L609" href="#L609">609</a>         } <strong class="jxr_keyword">catch</strong> (Exception e) {
+<a class="jxr_linenumber" name="L610" href="#L610">610</a>             <em class="jxr_comment">// Should never happen.</em>
+<a class="jxr_linenumber" name="L611" href="#L611">611</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> RuntimeException(<span class="jxr_string">"Unexpected"</span>, e);
+<a class="jxr_linenumber" name="L612" href="#L612">612</a>         }
+<a class="jxr_linenumber" name="L613" href="#L613">613</a> 
+<a class="jxr_linenumber" name="L614" href="#L614">614</a>         <strong class="jxr_keyword">if</strong> ((<strong class="jxr_keyword">double</strong>) numFailures / (<strong class="jxr_keyword">double</strong>) numTests &gt; 0.02) {
+<a class="jxr_linenumber" name="L615" href="#L615">615</a>             Assert.fail(generator + <span class="jxr_string">": Too many failures for n = "</span> + n +
+<a class="jxr_linenumber" name="L616" href="#L616">616</a>                         <span class="jxr_string">" ("</span> + numFailures + <span class="jxr_string">" out of "</span> + numTests + <span class="jxr_string">" tests failed)"</span>);
+<a class="jxr_linenumber" name="L617" href="#L617">617</a>         }
+<a class="jxr_linenumber" name="L618" href="#L618">618</a>     }
 <a class="jxr_linenumber" name="L619" href="#L619">619</a> 
-<a class="jxr_linenumber" name="L620" href="#L620">620</a>         <strong class="jxr_keyword">if</strong> ((<strong class="jxr_keyword">double</strong>) numFailures / (<strong class="jxr_keyword">double</strong>) numTests &gt; 0.02) {
-<a class="jxr_linenumber" name="L621" href="#L621">621</a>             Assert.fail(generator + <span class="jxr_string">": Too many failures for n = "</span> + n +
-<a class="jxr_linenumber" name="L622" href="#L622">622</a>                         <span class="jxr_string">" ("</span> + numFailures + <span class="jxr_string">" out of "</span> + numTests + <span class="jxr_string">" tests failed)"</span>);
-<a class="jxr_linenumber" name="L623" href="#L623">623</a>         }
-<a class="jxr_linenumber" name="L624" href="#L624">624</a>     }
-<a class="jxr_linenumber" name="L625" href="#L625">625</a> 
-<a class="jxr_linenumber" name="L626" href="#L626">626</a>     <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="L627" href="#L627">627</a> <em class="jxr_javadoccomment">     * @param rng Generator.</em>
-<a class="jxr_linenumber" name="L628" href="#L628">628</a> <em class="jxr_javadoccomment">     * @param chunkSize Size of the small buffer.</em>
-<a class="jxr_linenumber" name="L629" href="#L629">629</a> <em class="jxr_javadoccomment">     * @param numChunks Number of chunks that make the large buffer.</em>
-<a class="jxr_linenumber" name="L630" href="#L630">630</a> <em class="jxr_javadoccomment">     */</em>
-<a class="jxr_linenumber" name="L631" href="#L631">631</a>     <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">void</strong> checkNextBytesChunks(UniformRandomProvider rng,
-<a class="jxr_linenumber" name="L632" href="#L632">632</a>                                      <strong class="jxr_keyword">int</strong> chunkSize,
-<a class="jxr_linenumber" name="L633" href="#L633">633</a>                                      <strong class="jxr_keyword">int</strong> numChunks) {
-<a class="jxr_linenumber" name="L634" href="#L634">634</a>         <strong class="jxr_keyword">final</strong> byte[] b1 = <strong class="jxr_keyword">new</strong> byte[chunkSize * numChunks];
-<a class="jxr_linenumber" name="L635" href="#L635">635</a>         <strong class="jxr_keyword">final</strong> byte[] b2 = <strong class="jxr_keyword">new</strong> byte[chunkSize];
-<a class="jxr_linenumber" name="L636" href="#L636">636</a> 
-<a class="jxr_linenumber" name="L637" href="#L637">637</a>         <strong class="jxr_keyword">final</strong> RandomSource.State state = RandomSource.saveState(rng);
+<a class="jxr_linenumber" name="L620" href="#L620">620</a>     <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="L621" href="#L621">621</a> <em class="jxr_javadoccomment">     * @param rng Generator.</em>
+<a class="jxr_linenumber" name="L622" href="#L622">622</a> <em class="jxr_javadoccomment">     * @param chunkSize Size of the small buffer.</em>
+<a class="jxr_linenumber" name="L623" href="#L623">623</a> <em class="jxr_javadoccomment">     * @param numChunks Number of chunks that make the large buffer.</em>
+<a class="jxr_linenumber" name="L624" href="#L624">624</a> <em class="jxr_javadoccomment">     */</em>
+<a class="jxr_linenumber" name="L625" href="#L625">625</a>     <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">void</strong> checkNextBytesChunks(UniformRandomProvider rng,
+<a class="jxr_linenumber" name="L626" href="#L626">626</a>                                      <strong class="jxr_keyword">int</strong> chunkSize,
+<a class="jxr_linenumber" name="L627" href="#L627">627</a>                                      <strong class="jxr_keyword">int</strong> numChunks) {
+<a class="jxr_linenumber" name="L628" href="#L628">628</a>         <strong class="jxr_keyword">final</strong> byte[] b1 = <strong class="jxr_keyword">new</strong> byte[chunkSize * numChunks];
+<a class="jxr_linenumber" name="L629" href="#L629">629</a>         <strong class="jxr_keyword">final</strong> byte[] b2 = <strong class="jxr_keyword">new</strong> byte[chunkSize];
+<a class="jxr_linenumber" name="L630" href="#L630">630</a> 
+<a class="jxr_linenumber" name="L631" href="#L631">631</a>         <strong class="jxr_keyword">final</strong> RandomSource.State state = RandomSource.saveState(rng);
+<a class="jxr_linenumber" name="L632" href="#L632">632</a> 
+<a class="jxr_linenumber" name="L633" href="#L633">633</a>         <em class="jxr_comment">// Generate the chunks in a single call.</em>
+<a class="jxr_linenumber" name="L634" href="#L634">634</a>         rng.nextBytes(b1);
+<a class="jxr_linenumber" name="L635" href="#L635">635</a> 
+<a class="jxr_linenumber" name="L636" href="#L636">636</a>         <em class="jxr_comment">// Reset to previous state.</em>
+<a class="jxr_linenumber" name="L637" href="#L637">637</a>         RandomSource.restoreState(rng, state);
 <a class="jxr_linenumber" name="L638" href="#L638">638</a> 
-<a class="jxr_linenumber" name="L639" href="#L639">639</a>         <em class="jxr_comment">// Generate the chunks in a single call.</em>
-<a class="jxr_linenumber" name="L640" href="#L640">640</a>         rng.nextBytes(b1);
-<a class="jxr_linenumber" name="L641" href="#L641">641</a> 
-<a class="jxr_linenumber" name="L642" href="#L642">642</a>         <em class="jxr_comment">// Reset to previous state.</em>
-<a class="jxr_linenumber" name="L643" href="#L643">643</a>         RandomSource.restoreState(rng, state);
-<a class="jxr_linenumber" name="L644" href="#L644">644</a> 
-<a class="jxr_linenumber" name="L645" href="#L645">645</a>         <em class="jxr_comment">// Generate the chunks in consecutive calls.</em>
-<a class="jxr_linenumber" name="L646" href="#L646">646</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; numChunks; i++) {
-<a class="jxr_linenumber" name="L647" href="#L647">647</a>             rng.nextBytes(b2);
-<a class="jxr_linenumber" name="L648" href="#L648">648</a>         }
-<a class="jxr_linenumber" name="L649" href="#L649">649</a> 
-<a class="jxr_linenumber" name="L650" href="#L650">650</a>         <em class="jxr_comment">// Store last "chunkSize" bytes of b1 into b3.</em>
-<a class="jxr_linenumber" name="L651" href="#L651">651</a>         <strong class="jxr_keyword">final</strong> byte[] b3 = <strong class="jxr_keyword">new</strong> byte[chunkSize];
-<a class="jxr_linenumber" name="L652" href="#L652">652</a>         System.arraycopy(b1, b1.length - b3.length, b3, 0, b3.length);
+<a class="jxr_linenumber" name="L639" href="#L639">639</a>         <em class="jxr_comment">// Generate the chunks in consecutive calls.</em>
+<a class="jxr_linenumber" name="L640" href="#L640">640</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; numChunks; i++) {
+<a class="jxr_linenumber" name="L641" href="#L641">641</a>             rng.nextBytes(b2);
+<a class="jxr_linenumber" name="L642" href="#L642">642</a>         }
+<a class="jxr_linenumber" name="L643" href="#L643">643</a> 
+<a class="jxr_linenumber" name="L644" href="#L644">644</a>         <em class="jxr_comment">// Store last "chunkSize" bytes of b1 into b3.</em>
+<a class="jxr_linenumber" name="L645" href="#L645">645</a>         <strong class="jxr_keyword">final</strong> byte[] b3 = <strong class="jxr_keyword">new</strong> byte[chunkSize];
+<a class="jxr_linenumber" name="L646" href="#L646">646</a>         System.arraycopy(b1, b1.length - b3.length, b3, 0, b3.length);
+<a class="jxr_linenumber" name="L647" href="#L647">647</a> 
+<a class="jxr_linenumber" name="L648" href="#L648">648</a>         <em class="jxr_comment">// Sequence of calls must be the same.</em>
+<a class="jxr_linenumber" name="L649" href="#L649">649</a>         Assert.assertArrayEquals(<span class="jxr_string">"chunkSize="</span> + chunkSize + <span class="jxr_string">" numChunks="</span> + numChunks,
+<a class="jxr_linenumber" name="L650" href="#L650">650</a>                                  b2, b3);
+<a class="jxr_linenumber" name="L651" href="#L651">651</a>     }
+<a class="jxr_linenumber" name="L652" href="#L652">652</a> }
 <a class="jxr_linenumber" name="L653" href="#L653">653</a> 
-<a class="jxr_linenumber" name="L654" href="#L654">654</a>         <em class="jxr_comment">// Sequence of calls must be the same.</em>
-<a class="jxr_linenumber" name="L655" href="#L655">655</a>         Assert.assertArrayEquals(<span class="jxr_string">"chunkSize="</span> + chunkSize + <span class="jxr_string">" numChunks="</span> + numChunks,
-<a class="jxr_linenumber" name="L656" href="#L656">656</a>                                  b2, b3);
-<a class="jxr_linenumber" name="L657" href="#L657">657</a>     }
-<a class="jxr_linenumber" name="L658" href="#L658">658</a> }
-<a class="jxr_linenumber" name="L659" href="#L659">659</a> 
-<a class="jxr_linenumber" name="L660" href="#L660">660</a> <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="L661" href="#L661">661</a> <em class="jxr_javadoccomment"> * Dummy class for checking that restoring fails when an invalid state is used.</em>
-<a class="jxr_linenumber" name="L662" href="#L662">662</a> <em class="jxr_javadoccomment"> */</em>
-<a class="jxr_linenumber" name="L663" href="#L663">663</a> <strong class="jxr_keyword">class</strong> <a href="../../../../org/apache/commons/rng/ProvidersCommonParametricTest.html">DummyGenerator</a> <strong class="jxr_keyword">extends</strong> org.apache.commons.rng.internal.source32.IntProvider {
-<a class="jxr_linenumber" name="L664" href="#L664">664</a>     <em class="jxr_javadoccomment">/** State. */</em>
-<a class="jxr_linenumber" name="L665" href="#L665">665</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">int</strong> state;
+<a class="jxr_linenumber" name="L654" href="#L654">654</a> <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="L655" href="#L655">655</a> <em class="jxr_javadoccomment"> * Dummy class for checking that restoring fails when an invalid state is used.</em>
+<a class="jxr_linenumber" name="L656" href="#L656">656</a> <em class="jxr_javadoccomment"> */</em>
+<a class="jxr_linenumber" name="L657" href="#L657">657</a> <strong class="jxr_keyword">class</strong> <a href="../../../../org/apache/commons/rng/ProvidersCommonParametricTest.html">DummyGenerator</a> <strong class="jxr_keyword">extends</strong> org.apache.commons.rng.internal.source32.IntProvider {
+<a class="jxr_linenumber" name="L658" href="#L658">658</a>     <em class="jxr_javadoccomment">/** State. */</em>
+<a class="jxr_linenumber" name="L659" href="#L659">659</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">int</strong> state;
+<a class="jxr_linenumber" name="L660" href="#L660">660</a> 
+<a class="jxr_linenumber" name="L661" href="#L661">661</a>     <em class="jxr_javadoccomment">/** {@inheritDoc} */</em>
+<a class="jxr_linenumber" name="L662" href="#L662">662</a>     @Override
+<a class="jxr_linenumber" name="L663" href="#L663">663</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">int</strong> next() {
+<a class="jxr_linenumber" name="L664" href="#L664">664</a>         <strong class="jxr_keyword">return</strong> 4; <em class="jxr_comment">// https://www.xkcd.com/221/</em>
+<a class="jxr_linenumber" name="L665" href="#L665">665</a>     }
 <a class="jxr_linenumber" name="L666" href="#L666">666</a> 
 <a class="jxr_linenumber" name="L667" href="#L667">667</a>     <em class="jxr_javadoccomment">/** {@inheritDoc} */</em>
 <a class="jxr_linenumber" name="L668" href="#L668">668</a>     @Override
-<a class="jxr_linenumber" name="L669" href="#L669">669</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">int</strong> next() {

[... 24 lines stripped ...]



Mime
View raw message