http://git-wip-us.apache.org/repos/asf/commons-rng/blob/d1b3113a/commons-rng-core/site-content/.svn/pristine/01/0183a626dc1383e47b9da5f42bf0f33217aff938.svn-base ---------------------------------------------------------------------- diff --git a/commons-rng-core/site-content/.svn/pristine/01/0183a626dc1383e47b9da5f42bf0f33217aff938.svn-base b/commons-rng-core/site-content/.svn/pristine/01/0183a626dc1383e47b9da5f42bf0f33217aff938.svn-base new file mode 100644 index 0000000..80ed64f --- /dev/null +++ b/commons-rng-core/site-content/.svn/pristine/01/0183a626dc1383e47b9da5f42bf0f33217aff938.svn-base @@ -0,0 +1,131 @@ +<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../.resources/report.css" type="text/css"/><link rel="shortcut icon" href="../.resources/report.gif" type="image/gif"/><title>IntProvider.java</title><link rel="stylesheet" href="../.resources/prettify.css" type="text/css"/><script type="text/javascript" src="../.resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../.sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Commons Rng</a> > <a href="index.source.html" class="el_package">org.apache.commons.rng.internal.source32</a> > <span class="el_source">IntProvider.java</span ></div><h1>IntProvider.java</h1><pre class="source lang-java linenums">/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.rng.internal.source32; + +import org.apache.commons.rng.internal.util.NumberFactory; +import org.apache.commons.rng.internal.BaseProvider; + +/** + * Base class for all implementations that provide an {@code int}-based + * source randomness. + */ +<span class="fc" id="L27">public abstract class IntProvider</span> + extends BaseProvider + implements RandomIntSource { + + /** {@inheritDoc} */ + @Override + public abstract int next(); + + /** {@inheritDoc} */ + @Override + public int nextInt() { +<span class="fc" id="L38"> return next();</span> + } + + /** {@inheritDoc} */ + @Override + public boolean nextBoolean() { +<span class="fc" id="L44"> return NumberFactory.makeBoolean(nextInt());</span> + } + + /** {@inheritDoc} */ + @Override + public double nextDouble() { +<span class="fc" id="L50"> return NumberFactory.makeDouble(nextInt(), nextInt());</span> + } + + /** {@inheritDoc} */ + @Override + public float nextFloat() { +<span class="fc" id="L56"> return NumberFactory.makeFloat(nextInt());</span> + } + + /** {@inheritDoc} */ + @Override + public long nextLong() { +<span class="fc" id="L62"> return NumberFactory.makeLong(nextInt(), nextInt());</span> + } + + /** {@inheritDoc} */ + @Override + public void nextBytes(byte[] bytes) { +<span class="fc" id="L68"> nextBytesFill(this, bytes, 0, bytes.length);</span> +<span class="fc" id="L69"> }</span> + + /** {@inheritDoc} */ + @Override + public void nextBytes(byte[] bytes, + int start, + int len) { +<span class="fc" id="L76"> checkIndex(0, bytes.length - 1, start);</span> +<span class="fc" id="L77"> checkIndex(0, bytes.length - start, len);</span> + +<span class="fc" id="L79"> nextBytesFill(this, bytes, start, len);</span> +<span class="fc" id="L80"> }</span> + + /** + * Generates random bytes and places them into a user-supplied array. + * + * <p> + * The array is filled with bytes extracted from random {@code int} values. + * This implies that the number of random bytes generated may be larger than + * the length of the byte array. + * </p> + * + * @param source Source of randomness. + * @param bytes Array in which to put the generated bytes. Cannot be null. + * @param start Index at which to start inserting the generated bytes. + * @param len Number of bytes to insert. + */ + static void nextBytesFill(RandomIntSource source, + byte[] bytes, + int start, + int len) { +<span class="fc" id="L100"> int index = start; // Index of first insertion.</span> + + // Index of first insertion plus multiple of 4 part of length + // (i.e. length with 2 least significant bits unset). +<span class="fc" id="L104"> final int indexLoopLimit = index + (len & 0x7ffffffc);</span> + + // Start filling in the byte array, 4 bytes at a time. +<span class="fc bfc" id="L107" title="All 2 branches covered."> while (index < indexLoopLimit) {</span> +<span class="fc" id="L108"> final int random = source.next();</span> +<span class="fc" id="L109"> bytes[index++] = (byte) random;</span> +<span class="fc" id="L110"> bytes[index++] = (byte) (random >>> 8);</span> +<span class="fc" id="L111"> bytes[index++] = (byte) (random >>> 16);</span> +<span class="fc" id="L112"> bytes[index++] = (byte) (random >>> 24);</span> +<span class="fc" id="L113"> }</span> + +<span class="fc" id="L115"> final int indexLimit = start + len; // Index of last insertion + 1.</span> + + // Fill in the remaining bytes. +<span class="fc bfc" id="L118" title="All 2 branches covered."> if (index < indexLimit) {</span> +<span class="fc" id="L119"> int random = source.next();</span> + while (true) { +<span class="fc" id="L121"> bytes[index++] = (byte) random;</span> +<span class="fc bfc" id="L122" title="All 2 branches covered."> if (index < indexLimit) {</span> +<span class="fc" id="L123"> random >>>= 8;</span> + } else { + break; + } + } + } +<span class="fc" id="L129"> }</span> +} +</pre><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.7.5.201505241946</span></div></body></html> \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-rng/blob/d1b3113a/commons-rng-core/site-content/.svn/pristine/01/01d015d1a8ee81a57dda1c852498aebf8fd9a7fc.svn-base ---------------------------------------------------------------------- diff --git a/commons-rng-core/site-content/.svn/pristine/01/01d015d1a8ee81a57dda1c852498aebf8fd9a7fc.svn-base b/commons-rng-core/site-content/.svn/pristine/01/01d015d1a8ee81a57dda1c852498aebf8fd9a7fc.svn-base new file mode 100644 index 0000000..004079c --- /dev/null +++ b/commons-rng-core/site-content/.svn/pristine/01/01d015d1a8ee81a57dda1c852498aebf8fd9a7fc.svn-base @@ -0,0 +1,69 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head><meta http-equiv="content-type" content="text/html; charset=UTF-8" /> +<title>Well19937c xref</title> +<link type="text/css" rel="stylesheet" href="../../../../../../stylesheet.css" /> +</head> +<body> +<div id="overview"><a href="../../../../../../../apidocs/org/apache/commons/rng/internal/source32/Well19937c.html">View Javadoc</a></div><pre> +<a class="jxr_linenumber" name="L1" href="#L1">1</a> <em class="jxr_comment">/*</em> +<a class="jxr_linenumber" name="L2" href="#L2">2</a> <em class="jxr_comment"> * Licensed to the Apache Software Foundation (ASF) under one or more</em> +<a class="jxr_linenumber" name="L3" href="#L3">3</a> <em class="jxr_comment"> * contributor license agreements. See the NOTICE file distributed with</em> +<a class="jxr_linenumber" name="L4" href="#L4">4</a> <em class="jxr_comment"> * this work for additional information regarding copyright ownership.</em> +<a class="jxr_linenumber" name="L5" href="#L5">5</a> <em class="jxr_comment"> * The ASF licenses this file to You under the Apache License, Version 2.0</em> +<a class="jxr_linenumber" name="L6" href="#L6">6</a> <em class="jxr_comment"> * (the "License"); you may not use this file except in compliance with</em> +<a class="jxr_linenumber" name="L7" href="#L7">7</a> <em class="jxr_comment"> * the License. You may obtain a copy of the License at</em> +<a class="jxr_linenumber" name="L8" href="#L8">8</a> <em class="jxr_comment"> *</em> +<a class="jxr_linenumber" name="L9" href="#L9">9</a> <em class="jxr_comment"> * <a href="http://www.apache.org/licenses/LICENSE-2." target="alexandria_uri">http://www.apache.org/licenses/LICENSE-2.</a>0</em> +<a class="jxr_linenumber" name="L10" href="#L10">10</a> <em class="jxr_comment"> *</em> +<a class="jxr_linenumber" name="L11" href="#L11">11</a> <em class="jxr_comment"> * Unless required by applicable law or agreed to in writing, software</em> +<a class="jxr_linenumber" name="L12" href="#L12">12</a> <em class="jxr_comment"> * distributed under the License is distributed on an "AS IS" BASIS,</em> +<a class="jxr_linenumber" name="L13" href="#L13">13</a> <em class="jxr_comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</em> +<a class="jxr_linenumber" name="L14" href="#L14">14</a> <em class="jxr_comment"> * See the License for the specific language governing permissions and</em> +<a class="jxr_linenumber" name="L15" href="#L15">15</a> <em class="jxr_comment"> * limitations under the License.</em> +<a class="jxr_linenumber" name="L16" href="#L16">16</a> <em class="jxr_comment"> */</em> +<a class="jxr_linenumber" name="L17" href="#L17">17</a> <strong class="jxr_keyword">package</strong> org.apache.commons.rng.internal.source32; +<a class="jxr_linenumber" name="L18" href="#L18">18</a> +<a class="jxr_linenumber" name="L19" href="#L19">19</a> <em class="jxr_javadoccomment">/**</em> +<a class="jxr_linenumber" name="L20" href="#L20">20</a> <em class="jxr_javadoccomment"> * This class implements the WELL19937c pseudo-random number generator</em> +<a class="jxr_linenumber" name="L21" href="#L21">21</a> <em class="jxr_javadoccomment"> * from Fran&ccedil;ois Panneton, Pierre L'Ecuyer and Makoto Matsumoto.</em> +<a class="jxr_linenumber" name="L22" href="#L22">22</a> <em class="jxr_javadoccomment"> * <p></em> +<a class="jxr_linenumber" name="L23" href="#L23">23</a> <em class="jxr_javadoccomment"> * This generator is described in a paper by Fran&ccedil;ois Panneton,</em> +<a class="jxr_linenumber" name="L24" href="#L24">24</a> <em class="jxr_javadoccomment"> * Pierre L'Ecuyer and Makoto Matsumoto</em> +<a class="jxr_linenumber" name="L25" href="#L25">25</a> <em class="jxr_javadoccomment"> * <a href="<a href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng.pdf" target="alexandria_uri">http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng.pdf</a>"></em> +<a class="jxr_linenumber" name="L26" href="#L26">26</a> <em class="jxr_javadoccomment"> * Improved Long-Period Generators Based on Linear Recurrences Modulo 2</a></em> +<a class="jxr_linenumber" name="L27" href="#L27">27</a> <em class="jxr_javadoccomment"> * ACM Transactions on Mathematical Software, 32, 1 (2006).</em> +<a class="jxr_linenumber" name="L28" href="#L28">28</a> <em class="jxr_javadoccomment"> * The errata for the paper are in</em> +<a class="jxr_linenumber" name="L29" href="#L29">29</a> <em class="jxr_javadoccomment"> * <a href="<a href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng-errata.txt" target="alexandria_uri">http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng-errata.txt</a>">wellrng-errata.txt</a>.</em> +<a class="jxr_linenumber" name="L30" href="#L30">30</a> <em class="jxr_javadoccomment"> * </p></em> +<a class="jxr_linenumber" name="L31" href="#L31">31</a> <em class="jxr_javadoccomment"> *</em> +<a class="jxr_linenumber" name="L32" href="#L32">32</a> <em class="jxr_javadoccomment"> * @see <a href="<a href="http://www.iro.umontreal.ca/~panneton/WELLRNG.html" target="alexandria_uri">http://www.iro.umontreal.ca/~panneton/WELLRNG.html</a>">WELL Random number generator</a></em> +<a class="jxr_linenumber" name="L33" href="#L33">33</a> <em class="jxr_javadoccomment"> * @since 1.0</em> +<a class="jxr_linenumber" name="L34" href="#L34">34</a> <em class="jxr_javadoccomment"> */</em> +<a class="jxr_linenumber" name="L35" href="#L35">35</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">class</strong> <a href="../../../../../../org/apache/commons/rng/internal/source32/Well19937c.html">Well19937c</a> <strong class="jxr_keyword">extends</strong> <a href="../../../../../../org/apache/commons/rng/internal/source32/Well19937a.html">Well19937a</a> { +<a class="jxr_linenumber" name="L36" href="#L36">36</a> <em class="jxr_javadoccomment">/**</em> +<a class="jxr_linenumber" name="L37" href="#L37">37</a> <em class="jxr_javadoccomment"> * Creates a new random number generator.</em> +<a class="jxr_linenumber" name="L38" href="#L38">38</a> <em class="jxr_javadoccomment"> *</em> +<a class="jxr_linenumber" name="L39" href="#L39">39</a> <em class="jxr_javadoccomment"> * @param seed Initial seed.</em> +<a class="jxr_linenumber" name="L40" href="#L40">40</a> <em class="jxr_javadoccomment"> */</em> +<a class="jxr_linenumber" name="L41" href="#L41">41</a> <strong class="jxr_keyword">public</strong> <a href="../../../../../../org/apache/commons/rng/internal/source32/Well19937c.html">Well19937c</a>(<strong class="jxr_keyword">int</strong>[] seed) { +<a class="jxr_linenumber" name="L42" href="#L42">42</a> <strong class="jxr_keyword">super</strong>(seed); +<a class="jxr_linenumber" name="L43" href="#L43">43</a> } +<a class="jxr_linenumber" name="L44" href="#L44">44</a> +<a class="jxr_linenumber" name="L45" href="#L45">45</a> <em class="jxr_javadoccomment">/** {@inheritDoc} */</em> +<a class="jxr_linenumber" name="L46" href="#L46">46</a> @Override +<a class="jxr_linenumber" name="L47" href="#L47">47</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">int</strong> next() { +<a class="jxr_linenumber" name="L48" href="#L48">48</a> <strong class="jxr_keyword">int</strong> z4 = <strong class="jxr_keyword">super</strong>.next(); +<a class="jxr_linenumber" name="L49" href="#L49">49</a> +<a class="jxr_linenumber" name="L50" href="#L50">50</a> <em class="jxr_comment">// Matsumoto-Kurita tempering to get a maximally equidistributed generator.</em> +<a class="jxr_linenumber" name="L51" href="#L51">51</a> z4 ^= (z4 << 7) & 0xe46e1700; +<a class="jxr_linenumber" name="L52" href="#L52">52</a> z4 ^= (z4 << 15) & 0x9b868000; +<a class="jxr_linenumber" name="L53" href="#L53">53</a> +<a class="jxr_linenumber" name="L54" href="#L54">54</a> <strong class="jxr_keyword">return</strong> z4; +<a class="jxr_linenumber" name="L55" href="#L55">55</a> } +<a class="jxr_linenumber" name="L56" href="#L56">56</a> } +</pre> +<hr/> +<div id="footer">Copyright © 2016 <a href="https://www.apache.org/">The Apache Software Foundation</a>. All rights reserved.</div> +</body> +</html> \ No newline at end of file