commons-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r996528 [8/35] - 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/inter...
Date Fri, 02 Sep 2016 16:37:59 GMT
Modified: websites/production/commons/content/proper/commons-rng/apidocs/src-html/org/apache/commons/rng/internal/ProviderBuilder.RandomSourceInternal.html
==============================================================================
--- websites/production/commons/content/proper/commons-rng/apidocs/src-html/org/apache/commons/rng/internal/ProviderBuilder.RandomSourceInternal.html (original)
+++ websites/production/commons/content/proper/commons-rng/apidocs/src-html/org/apache/commons/rng/internal/ProviderBuilder.RandomSourceInternal.html Fri Sep  2 16:37:56 2016
@@ -43,318 +43,349 @@
 <span class="sourceLineNo">035</span>import org.apache.commons.rng.internal.util.LongArray2IntArray;<a name="line.35"></a>
 <span class="sourceLineNo">036</span>import org.apache.commons.rng.internal.util.LongArray2Long;<a name="line.36"></a>
 <span class="sourceLineNo">037</span>import org.apache.commons.rng.internal.util.IntArray2Int;<a name="line.37"></a>
-<span class="sourceLineNo">038</span>import org.apache.commons.rng.internal.util.SeedConverter;<a name="line.38"></a>
-<span class="sourceLineNo">039</span>import org.apache.commons.rng.internal.util.SeedConverterComposer;<a name="line.39"></a>
-<span class="sourceLineNo">040</span>import org.apache.commons.rng.internal.source32.JDKRandom;<a name="line.40"></a>
-<span class="sourceLineNo">041</span>import org.apache.commons.rng.internal.source32.Well512a;<a name="line.41"></a>
-<span class="sourceLineNo">042</span>import org.apache.commons.rng.internal.source32.Well1024a;<a name="line.42"></a>
-<span class="sourceLineNo">043</span>import org.apache.commons.rng.internal.source32.Well19937a;<a name="line.43"></a>
-<span class="sourceLineNo">044</span>import org.apache.commons.rng.internal.source32.Well19937c;<a name="line.44"></a>
-<span class="sourceLineNo">045</span>import org.apache.commons.rng.internal.source32.Well44497a;<a name="line.45"></a>
-<span class="sourceLineNo">046</span>import org.apache.commons.rng.internal.source32.Well44497b;<a name="line.46"></a>
-<span class="sourceLineNo">047</span>import org.apache.commons.rng.internal.source32.ISAACRandom;<a name="line.47"></a>
-<span class="sourceLineNo">048</span>import org.apache.commons.rng.internal.source32.MersenneTwister;<a name="line.48"></a>
-<span class="sourceLineNo">049</span>import org.apache.commons.rng.internal.source64.SplitMix64;<a name="line.49"></a>
-<span class="sourceLineNo">050</span>import org.apache.commons.rng.internal.source64.XorShift1024Star;<a name="line.50"></a>
-<span class="sourceLineNo">051</span>import org.apache.commons.rng.internal.source64.TwoCmres;<a name="line.51"></a>
-<span class="sourceLineNo">052</span>import org.apache.commons.rng.internal.source64.MersenneTwister64;<a name="line.52"></a>
-<span class="sourceLineNo">053</span><a name="line.53"></a>
-<span class="sourceLineNo">054</span>/**<a name="line.54"></a>
-<span class="sourceLineNo">055</span> * RNG builder.<a name="line.55"></a>
-<span class="sourceLineNo">056</span> * &lt;p&gt;<a name="line.56"></a>
-<span class="sourceLineNo">057</span> * It uses reflection to find the factory method of the RNG implementation,<a name="line.57"></a>
-<span class="sourceLineNo">058</span> * and performs seed type conversions.<a name="line.58"></a>
-<span class="sourceLineNo">059</span> * &lt;/p&gt;<a name="line.59"></a>
-<span class="sourceLineNo">060</span> */<a name="line.60"></a>
-<span class="sourceLineNo">061</span>public class ProviderBuilder {<a name="line.61"></a>
-<span class="sourceLineNo">062</span>    /** Error message. */<a name="line.62"></a>
-<span class="sourceLineNo">063</span>    private static final String INTERNAL_ERROR_MSG = "Internal error: Please file a bug report";<a name="line.63"></a>
-<span class="sourceLineNo">064</span>    /** Length of the seed array (for random seed). */<a name="line.64"></a>
-<span class="sourceLineNo">065</span>    private static final int RANDOM_SEED_ARRAY_SIZE = 128;<a name="line.65"></a>
-<span class="sourceLineNo">066</span>    /** Seed converter. */<a name="line.66"></a>
-<span class="sourceLineNo">067</span>    private static final Long2Int LONG_TO_INT = new Long2Int();<a name="line.67"></a>
-<span class="sourceLineNo">068</span>    /** Seed converter. */<a name="line.68"></a>
-<span class="sourceLineNo">069</span>    private static final Int2Long INT_TO_LONG = new Int2Long();<a name="line.69"></a>
+<span class="sourceLineNo">038</span>import org.apache.commons.rng.internal.util.ByteArray2IntArray;<a name="line.38"></a>
+<span class="sourceLineNo">039</span>import org.apache.commons.rng.internal.util.ByteArray2LongArray;<a name="line.39"></a>
+<span class="sourceLineNo">040</span>import org.apache.commons.rng.internal.util.SeedConverter;<a name="line.40"></a>
+<span class="sourceLineNo">041</span>import org.apache.commons.rng.internal.util.SeedConverterComposer;<a name="line.41"></a>
+<span class="sourceLineNo">042</span>import org.apache.commons.rng.internal.source32.JDKRandom;<a name="line.42"></a>
+<span class="sourceLineNo">043</span>import org.apache.commons.rng.internal.source32.Well512a;<a name="line.43"></a>
+<span class="sourceLineNo">044</span>import org.apache.commons.rng.internal.source32.Well1024a;<a name="line.44"></a>
+<span class="sourceLineNo">045</span>import org.apache.commons.rng.internal.source32.Well19937a;<a name="line.45"></a>
+<span class="sourceLineNo">046</span>import org.apache.commons.rng.internal.source32.Well19937c;<a name="line.46"></a>
+<span class="sourceLineNo">047</span>import org.apache.commons.rng.internal.source32.Well44497a;<a name="line.47"></a>
+<span class="sourceLineNo">048</span>import org.apache.commons.rng.internal.source32.Well44497b;<a name="line.48"></a>
+<span class="sourceLineNo">049</span>import org.apache.commons.rng.internal.source32.ISAACRandom;<a name="line.49"></a>
+<span class="sourceLineNo">050</span>import org.apache.commons.rng.internal.source32.MersenneTwister;<a name="line.50"></a>
+<span class="sourceLineNo">051</span>import org.apache.commons.rng.internal.source32.MultiplyWithCarry256;<a name="line.51"></a>
+<span class="sourceLineNo">052</span>import org.apache.commons.rng.internal.source32.KISSRandom;<a name="line.52"></a>
+<span class="sourceLineNo">053</span>import org.apache.commons.rng.internal.source64.SplitMix64;<a name="line.53"></a>
+<span class="sourceLineNo">054</span>import org.apache.commons.rng.internal.source64.XorShift1024Star;<a name="line.54"></a>
+<span class="sourceLineNo">055</span>import org.apache.commons.rng.internal.source64.TwoCmres;<a name="line.55"></a>
+<span class="sourceLineNo">056</span>import org.apache.commons.rng.internal.source64.MersenneTwister64;<a name="line.56"></a>
+<span class="sourceLineNo">057</span><a name="line.57"></a>
+<span class="sourceLineNo">058</span>/**<a name="line.58"></a>
+<span class="sourceLineNo">059</span> * RNG builder.<a name="line.59"></a>
+<span class="sourceLineNo">060</span> * &lt;p&gt;<a name="line.60"></a>
+<span class="sourceLineNo">061</span> * It uses reflection to find the factory method of the RNG implementation,<a name="line.61"></a>
+<span class="sourceLineNo">062</span> * and performs seed type conversions.<a name="line.62"></a>
+<span class="sourceLineNo">063</span> * &lt;/p&gt;<a name="line.63"></a>
+<span class="sourceLineNo">064</span> */<a name="line.64"></a>
+<span class="sourceLineNo">065</span>public class ProviderBuilder {<a name="line.65"></a>
+<span class="sourceLineNo">066</span>    /** Error message. */<a name="line.66"></a>
+<span class="sourceLineNo">067</span>    private static final String INTERNAL_ERROR_MSG = "Internal error: Please file a bug report";<a name="line.67"></a>
+<span class="sourceLineNo">068</span>    /** Length of the seed array (for random seed). */<a name="line.68"></a>
+<span class="sourceLineNo">069</span>    private static final int RANDOM_SEED_ARRAY_SIZE = 128;<a name="line.69"></a>
 <span class="sourceLineNo">070</span>    /** Seed converter. */<a name="line.70"></a>
-<span class="sourceLineNo">071</span>    private static final Long2IntArray LONG_TO_INT_ARRAY = new Long2IntArray(RANDOM_SEED_ARRAY_SIZE);<a name="line.71"></a>
+<span class="sourceLineNo">071</span>    private static final Long2Int LONG_TO_INT = new Long2Int();<a name="line.71"></a>
 <span class="sourceLineNo">072</span>    /** Seed converter. */<a name="line.72"></a>
-<span class="sourceLineNo">073</span>    private static final Long2LongArray LONG_TO_LONG_ARRAY = new Long2LongArray(RANDOM_SEED_ARRAY_SIZE);<a name="line.73"></a>
+<span class="sourceLineNo">073</span>    private static final Int2Long INT_TO_LONG = new Int2Long();<a name="line.73"></a>
 <span class="sourceLineNo">074</span>    /** Seed converter. */<a name="line.74"></a>
-<span class="sourceLineNo">075</span>    private static final LongArray2Long LONG_ARRAY_TO_LONG = new LongArray2Long();<a name="line.75"></a>
+<span class="sourceLineNo">075</span>    private static final Long2IntArray LONG_TO_INT_ARRAY = new Long2IntArray(RANDOM_SEED_ARRAY_SIZE);<a name="line.75"></a>
 <span class="sourceLineNo">076</span>    /** Seed converter. */<a name="line.76"></a>
-<span class="sourceLineNo">077</span>    private static final IntArray2Int INT_ARRAY_TO_INT = new IntArray2Int();<a name="line.77"></a>
+<span class="sourceLineNo">077</span>    private static final Long2LongArray LONG_TO_LONG_ARRAY = new Long2LongArray(RANDOM_SEED_ARRAY_SIZE);<a name="line.77"></a>
 <span class="sourceLineNo">078</span>    /** Seed converter. */<a name="line.78"></a>
-<span class="sourceLineNo">079</span>    private static final LongArray2IntArray LONG_ARRAY_TO_INT_ARRAY = new LongArray2IntArray();<a name="line.79"></a>
+<span class="sourceLineNo">079</span>    private static final LongArray2Long LONG_ARRAY_TO_LONG = new LongArray2Long();<a name="line.79"></a>
 <span class="sourceLineNo">080</span>    /** Seed converter. */<a name="line.80"></a>
-<span class="sourceLineNo">081</span>    private static final IntArray2LongArray INT_ARRAY_TO_LONG_ARRAY = new IntArray2LongArray();<a name="line.81"></a>
-<span class="sourceLineNo">082</span>    /** Map to convert "Integer" seeds. */<a name="line.82"></a>
-<span class="sourceLineNo">083</span>    private static final Map&lt;Class&lt;?&gt;, SeedConverter&lt;Integer,?&gt;&gt; CONV_INT =<a name="line.83"></a>
-<span class="sourceLineNo">084</span>        new HashMap&lt;Class&lt;?&gt;, SeedConverter&lt;Integer,?&gt;&gt;();<a name="line.84"></a>
-<span class="sourceLineNo">085</span>    /** Map to convert "int[]" seeds. */<a name="line.85"></a>
-<span class="sourceLineNo">086</span>    private static final Map&lt;Class&lt;?&gt;, SeedConverter&lt;int[],?&gt;&gt; CONV_INT_ARRAY =<a name="line.86"></a>
-<span class="sourceLineNo">087</span>        new HashMap&lt;Class&lt;?&gt;, SeedConverter&lt;int[],?&gt;&gt;();<a name="line.87"></a>
-<span class="sourceLineNo">088</span>    /** Map to convert "Long" seeds. */<a name="line.88"></a>
-<span class="sourceLineNo">089</span>    private static final Map&lt;Class&lt;?&gt;, SeedConverter&lt;Long,?&gt;&gt; CONV_LONG =<a name="line.89"></a>
-<span class="sourceLineNo">090</span>        new HashMap&lt;Class&lt;?&gt;, SeedConverter&lt;Long,?&gt;&gt;();<a name="line.90"></a>
-<span class="sourceLineNo">091</span>    /** Map to convert "long[]" seeds. */<a name="line.91"></a>
-<span class="sourceLineNo">092</span>    private static final Map&lt;Class&lt;?&gt;, SeedConverter&lt;long[],?&gt;&gt; CONV_LONG_ARRAY =<a name="line.92"></a>
-<span class="sourceLineNo">093</span>        new HashMap&lt;Class&lt;?&gt;, SeedConverter&lt;long[],?&gt;&gt;();<a name="line.93"></a>
-<span class="sourceLineNo">094</span><a name="line.94"></a>
-<span class="sourceLineNo">095</span>    static {<a name="line.95"></a>
-<span class="sourceLineNo">096</span>        // Input seed type is "Long".<a name="line.96"></a>
-<span class="sourceLineNo">097</span>        // Key is the implementation's "native" seed type.<a name="line.97"></a>
-<span class="sourceLineNo">098</span>        CONV_LONG.put(Integer.class, LONG_TO_INT);<a name="line.98"></a>
-<span class="sourceLineNo">099</span>        CONV_LONG.put(Long.class, new NoOpConverter&lt;Long&gt;());<a name="line.99"></a>
-<span class="sourceLineNo">100</span>        CONV_LONG.put(int[].class, LONG_TO_INT_ARRAY);<a name="line.100"></a>
-<span class="sourceLineNo">101</span>        CONV_LONG.put(long[].class, LONG_TO_LONG_ARRAY);<a name="line.101"></a>
-<span class="sourceLineNo">102</span><a name="line.102"></a>
-<span class="sourceLineNo">103</span>        // Input seed type is "Integer".<a name="line.103"></a>
-<span class="sourceLineNo">104</span>        // Key is the implementation's "native" seed type.<a name="line.104"></a>
-<span class="sourceLineNo">105</span>        CONV_INT.put(Integer.class, new NoOpConverter&lt;Integer&gt;());<a name="line.105"></a>
-<span class="sourceLineNo">106</span>        CONV_INT.put(Long.class, INT_TO_LONG);<a name="line.106"></a>
-<span class="sourceLineNo">107</span>        CONV_INT.put(int[].class, new SeedConverterComposer&lt;Integer,Long,int[]&gt;(INT_TO_LONG, LONG_TO_INT_ARRAY));<a name="line.107"></a>
-<span class="sourceLineNo">108</span>        CONV_INT.put(long[].class, new SeedConverterComposer&lt;Integer,Long,long[]&gt;(INT_TO_LONG, LONG_TO_LONG_ARRAY));<a name="line.108"></a>
-<span class="sourceLineNo">109</span><a name="line.109"></a>
-<span class="sourceLineNo">110</span>        // Input seed type is "int[]".<a name="line.110"></a>
-<span class="sourceLineNo">111</span>        // Key is the implementation's "native" seed type.<a name="line.111"></a>
-<span class="sourceLineNo">112</span>        CONV_INT_ARRAY.put(Integer.class, INT_ARRAY_TO_INT);<a name="line.112"></a>
-<span class="sourceLineNo">113</span>        CONV_INT_ARRAY.put(Long.class, new SeedConverterComposer&lt;int[],Integer,Long&gt;(INT_ARRAY_TO_INT, INT_TO_LONG));<a name="line.113"></a>
-<span class="sourceLineNo">114</span>        CONV_INT_ARRAY.put(int[].class, new NoOpConverter&lt;int[]&gt;());<a name="line.114"></a>
-<span class="sourceLineNo">115</span>        CONV_INT_ARRAY.put(long[].class, INT_ARRAY_TO_LONG_ARRAY);<a name="line.115"></a>
-<span class="sourceLineNo">116</span><a name="line.116"></a>
-<span class="sourceLineNo">117</span>        // Input seed type is "long[]".<a name="line.117"></a>
-<span class="sourceLineNo">118</span>        // Key is the implementation's "native" seed type.<a name="line.118"></a>
-<span class="sourceLineNo">119</span>        CONV_LONG_ARRAY.put(Integer.class, new SeedConverterComposer&lt;long[],Long,Integer&gt;(LONG_ARRAY_TO_LONG, LONG_TO_INT));<a name="line.119"></a>
-<span class="sourceLineNo">120</span>        CONV_LONG_ARRAY.put(Long.class, LONG_ARRAY_TO_LONG);<a name="line.120"></a>
-<span class="sourceLineNo">121</span>        CONV_LONG_ARRAY.put(int[].class, LONG_ARRAY_TO_INT_ARRAY);<a name="line.121"></a>
-<span class="sourceLineNo">122</span>        CONV_LONG_ARRAY.put(long[].class, new NoOpConverter&lt;long[]&gt;());<a name="line.122"></a>
-<span class="sourceLineNo">123</span>    }<a name="line.123"></a>
-<span class="sourceLineNo">124</span><a name="line.124"></a>
-<span class="sourceLineNo">125</span>    /**<a name="line.125"></a>
-<span class="sourceLineNo">126</span>     * Class only contains static method.<a name="line.126"></a>
-<span class="sourceLineNo">127</span>     */<a name="line.127"></a>
-<span class="sourceLineNo">128</span>    private ProviderBuilder() {}<a name="line.128"></a>
-<span class="sourceLineNo">129</span><a name="line.129"></a>
-<span class="sourceLineNo">130</span>    /**<a name="line.130"></a>
-<span class="sourceLineNo">131</span>     * Creates a RNG instance.<a name="line.131"></a>
-<span class="sourceLineNo">132</span>     *<a name="line.132"></a>
-<span class="sourceLineNo">133</span>     * @param source RNG specification.<a name="line.133"></a>
-<span class="sourceLineNo">134</span>     * @param seed Seed value.  It can be {@code null} (in which case a<a name="line.134"></a>
-<span class="sourceLineNo">135</span>     * random value will be used).<a name="line.135"></a>
-<span class="sourceLineNo">136</span>     * @param args Additional arguments to the implementation's constructor.<a name="line.136"></a>
-<span class="sourceLineNo">137</span>     * @return a new RNG instance.<a name="line.137"></a>
-<span class="sourceLineNo">138</span>     * @throws UnsupportedOperationException if the seed type is invalid.<a name="line.138"></a>
-<span class="sourceLineNo">139</span>     */<a name="line.139"></a>
-<span class="sourceLineNo">140</span>    public static UniformRandomProvider create(RandomSourceInternal source,<a name="line.140"></a>
-<span class="sourceLineNo">141</span>                                               Object seed,<a name="line.141"></a>
-<span class="sourceLineNo">142</span>                                               Object[] args) {<a name="line.142"></a>
-<span class="sourceLineNo">143</span>        // Convert seed to native type.<a name="line.143"></a>
-<span class="sourceLineNo">144</span>        final Object nativeSeed = createSeed(source, seed);<a name="line.144"></a>
-<span class="sourceLineNo">145</span><a name="line.145"></a>
-<span class="sourceLineNo">146</span>        // Build a single array with all the arguments to be passed<a name="line.146"></a>
-<span class="sourceLineNo">147</span>        // (in the right order) to the constructor.<a name="line.147"></a>
-<span class="sourceLineNo">148</span>        final List&lt;Object&gt; all = new ArrayList&lt;Object&gt;();<a name="line.148"></a>
-<span class="sourceLineNo">149</span>        all.add(nativeSeed);<a name="line.149"></a>
-<span class="sourceLineNo">150</span>        if (args != null) {<a name="line.150"></a>
-<span class="sourceLineNo">151</span>            all.addAll(Arrays.asList(args));<a name="line.151"></a>
-<span class="sourceLineNo">152</span>        }<a name="line.152"></a>
-<span class="sourceLineNo">153</span><a name="line.153"></a>
-<span class="sourceLineNo">154</span>        // Instantiate.<a name="line.154"></a>
-<span class="sourceLineNo">155</span>        return create(createConstructor(source), all.toArray());<a name="line.155"></a>
-<span class="sourceLineNo">156</span>    }<a name="line.156"></a>
-<span class="sourceLineNo">157</span><a name="line.157"></a>
-<span class="sourceLineNo">158</span>    /**<a name="line.158"></a>
-<span class="sourceLineNo">159</span>     * Creates a native seed from any of the supported seed types.<a name="line.159"></a>
-<span class="sourceLineNo">160</span>     *<a name="line.160"></a>
-<span class="sourceLineNo">161</span>     * @param source Source.<a name="line.161"></a>
-<span class="sourceLineNo">162</span>     * @param seed Input seed.<a name="line.162"></a>
-<span class="sourceLineNo">163</span>     * @return the native seed.<a name="line.163"></a>
-<span class="sourceLineNo">164</span>     * @throw UnsupportedOperationException if the {@code seed} type is invalid.<a name="line.164"></a>
-<span class="sourceLineNo">165</span>     */<a name="line.165"></a>
-<span class="sourceLineNo">166</span>    private static Object createSeed(RandomSourceInternal source,<a name="line.166"></a>
-<span class="sourceLineNo">167</span>                                     Object seed) {<a name="line.167"></a>
-<span class="sourceLineNo">168</span>        Object nativeSeed = null;<a name="line.168"></a>
-<span class="sourceLineNo">169</span><a name="line.169"></a>
-<span class="sourceLineNo">170</span>        if (seed == null) {<a name="line.170"></a>
-<span class="sourceLineNo">171</span>            // Create a random seed of the appropriate native type.<a name="line.171"></a>
-<span class="sourceLineNo">172</span><a name="line.172"></a>
-<span class="sourceLineNo">173</span>            if (source.getSeed().equals(Integer.class)) {<a name="line.173"></a>
-<span class="sourceLineNo">174</span>                nativeSeed = SeedFactory.createInt();<a name="line.174"></a>
-<span class="sourceLineNo">175</span>            } else if (source.getSeed().equals(Long.class)) {<a name="line.175"></a>
-<span class="sourceLineNo">176</span>                nativeSeed = SeedFactory.createLong();<a name="line.176"></a>
-<span class="sourceLineNo">177</span>            } else if (source.getSeed().equals(int[].class)) {<a name="line.177"></a>
-<span class="sourceLineNo">178</span>                nativeSeed = SeedFactory.createIntArray(RANDOM_SEED_ARRAY_SIZE);<a name="line.178"></a>
-<span class="sourceLineNo">179</span>            } else if (source.getSeed().equals(long[].class)) {<a name="line.179"></a>
-<span class="sourceLineNo">180</span>                nativeSeed = SeedFactory.createLongArray(RANDOM_SEED_ARRAY_SIZE);<a name="line.180"></a>
-<span class="sourceLineNo">181</span>            }<a name="line.181"></a>
-<span class="sourceLineNo">182</span>        } else {<a name="line.182"></a>
-<span class="sourceLineNo">183</span>            // Convert to native type.<a name="line.183"></a>
-<span class="sourceLineNo">184</span><a name="line.184"></a>
-<span class="sourceLineNo">185</span>            if (seed instanceof Integer) {<a name="line.185"></a>
-<span class="sourceLineNo">186</span>                nativeSeed = CONV_INT.get(source.getSeed()).convert((Integer) seed);<a name="line.186"></a>
-<span class="sourceLineNo">187</span>            } else if (seed instanceof Long) {<a name="line.187"></a>
-<span class="sourceLineNo">188</span>                nativeSeed = CONV_LONG.get(source.getSeed()).convert((Long) seed);<a name="line.188"></a>
-<span class="sourceLineNo">189</span>            } else if (seed instanceof int[]) {<a name="line.189"></a>
-<span class="sourceLineNo">190</span>                nativeSeed = CONV_INT_ARRAY.get(source.getSeed()).convert((int[]) seed);<a name="line.190"></a>
-<span class="sourceLineNo">191</span>            } else if (seed instanceof long[]) {<a name="line.191"></a>
-<span class="sourceLineNo">192</span>                nativeSeed = CONV_LONG_ARRAY.get(source.getSeed()).convert((long[]) seed);<a name="line.192"></a>
-<span class="sourceLineNo">193</span>            }<a name="line.193"></a>
-<span class="sourceLineNo">194</span><a name="line.194"></a>
-<span class="sourceLineNo">195</span>            if (nativeSeed == null) {<a name="line.195"></a>
-<span class="sourceLineNo">196</span>                // Since the input seed was not null, getting here means that<a name="line.196"></a>
-<span class="sourceLineNo">197</span>                // no suitable converter is present in the maps.<a name="line.197"></a>
-<span class="sourceLineNo">198</span>                throw new UnsupportedOperationException("Unrecognized seed type");<a name="line.198"></a>
-<span class="sourceLineNo">199</span>            }<a name="line.199"></a>
-<span class="sourceLineNo">200</span><a name="line.200"></a>
-<span class="sourceLineNo">201</span>            if (!source.isNativeSeed(nativeSeed)) {<a name="line.201"></a>
-<span class="sourceLineNo">202</span>                // Conversion setup is wrong.<a name="line.202"></a>
-<span class="sourceLineNo">203</span>                throw new IllegalStateException(INTERNAL_ERROR_MSG);<a name="line.203"></a>
-<span class="sourceLineNo">204</span>            }<a name="line.204"></a>
-<span class="sourceLineNo">205</span>        }<a name="line.205"></a>
-<span class="sourceLineNo">206</span><a name="line.206"></a>
-<span class="sourceLineNo">207</span>        return nativeSeed;<a name="line.207"></a>
-<span class="sourceLineNo">208</span>    }<a name="line.208"></a>
-<span class="sourceLineNo">209</span><a name="line.209"></a>
-<span class="sourceLineNo">210</span>    /**<a name="line.210"></a>
-<span class="sourceLineNo">211</span>     * Creates a constructor.<a name="line.211"></a>
-<span class="sourceLineNo">212</span>     *<a name="line.212"></a>
-<span class="sourceLineNo">213</span>     * @param source RNG specification.<a name="line.213"></a>
-<span class="sourceLineNo">214</span>     * @return a RNG constructor.<a name="line.214"></a>
-<span class="sourceLineNo">215</span>     */<a name="line.215"></a>
-<span class="sourceLineNo">216</span>    private static Constructor&lt;?&gt; createConstructor(RandomSourceInternal source) {<a name="line.216"></a>
-<span class="sourceLineNo">217</span>        try {<a name="line.217"></a>
-<span class="sourceLineNo">218</span>            return source.getRng().getConstructor(source.getArgs());<a name="line.218"></a>
-<span class="sourceLineNo">219</span>        } catch (NoSuchMethodException e) {<a name="line.219"></a>
-<span class="sourceLineNo">220</span>            // Info in "RandomSourceInternal" is inconsistent with the<a name="line.220"></a>
-<span class="sourceLineNo">221</span>            // constructor of the implementation.<a name="line.221"></a>
-<span class="sourceLineNo">222</span>            throw new IllegalStateException(INTERNAL_ERROR_MSG, e);<a name="line.222"></a>
-<span class="sourceLineNo">223</span>        }<a name="line.223"></a>
-<span class="sourceLineNo">224</span>    }<a name="line.224"></a>
-<span class="sourceLineNo">225</span><a name="line.225"></a>
-<span class="sourceLineNo">226</span>    /**<a name="line.226"></a>
-<span class="sourceLineNo">227</span>     * Creates a RNG.<a name="line.227"></a>
-<span class="sourceLineNo">228</span>     *<a name="line.228"></a>
-<span class="sourceLineNo">229</span>     * @param rng RNG specification.<a name="line.229"></a>
-<span class="sourceLineNo">230</span>     * @param args Arguments to the implementation's constructor.<a name="line.230"></a>
-<span class="sourceLineNo">231</span>     * @return a new RNG instance.<a name="line.231"></a>
-<span class="sourceLineNo">232</span>     */<a name="line.232"></a>
-<span class="sourceLineNo">233</span>    private static UniformRandomProvider create(Constructor&lt;?&gt; rng,<a name="line.233"></a>
-<span class="sourceLineNo">234</span>                                                Object[] args) {<a name="line.234"></a>
-<span class="sourceLineNo">235</span>        try {<a name="line.235"></a>
-<span class="sourceLineNo">236</span>            return (UniformRandomProvider) rng.newInstance(args);<a name="line.236"></a>
-<span class="sourceLineNo">237</span>        } catch (InvocationTargetException e) {<a name="line.237"></a>
-<span class="sourceLineNo">238</span>            throw new IllegalStateException(INTERNAL_ERROR_MSG, e);<a name="line.238"></a>
-<span class="sourceLineNo">239</span>        } catch (InstantiationException e) {<a name="line.239"></a>
-<span class="sourceLineNo">240</span>            throw new IllegalStateException(INTERNAL_ERROR_MSG, e);<a name="line.240"></a>
-<span class="sourceLineNo">241</span>        } catch (IllegalAccessException e) {<a name="line.241"></a>
-<span class="sourceLineNo">242</span>            throw new IllegalStateException(INTERNAL_ERROR_MSG, e);<a name="line.242"></a>
-<span class="sourceLineNo">243</span>        }<a name="line.243"></a>
-<span class="sourceLineNo">244</span>    }<a name="line.244"></a>
-<span class="sourceLineNo">245</span><a name="line.245"></a>
-<span class="sourceLineNo">246</span>    /**<a name="line.246"></a>
-<span class="sourceLineNo">247</span>     * Identifiers of the generators.<a name="line.247"></a>
-<span class="sourceLineNo">248</span>     */<a name="line.248"></a>
-<span class="sourceLineNo">249</span>    public enum RandomSourceInternal {<a name="line.249"></a>
-<span class="sourceLineNo">250</span>        /** Source of randomness is {@link JDKRandom}. */<a name="line.250"></a>
-<span class="sourceLineNo">251</span>        JDK(JDKRandom.class,<a name="line.251"></a>
-<span class="sourceLineNo">252</span>            Long.class),<a name="line.252"></a>
-<span class="sourceLineNo">253</span>        /** Source of randomness is {@link Well512a}. */<a name="line.253"></a>
-<span class="sourceLineNo">254</span>        WELL_512_A(Well512a.class,<a name="line.254"></a>
-<span class="sourceLineNo">255</span>                   int[].class),<a name="line.255"></a>
-<span class="sourceLineNo">256</span>        /** Source of randomness is {@link Well1024a}. */<a name="line.256"></a>
-<span class="sourceLineNo">257</span>        WELL_1024_A(Well1024a.class,<a name="line.257"></a>
-<span class="sourceLineNo">258</span>                    int[].class),<a name="line.258"></a>
-<span class="sourceLineNo">259</span>        /** Source of randomness is {@link Well19937a}. */<a name="line.259"></a>
-<span class="sourceLineNo">260</span>        WELL_19937_A(Well19937a.class,<a name="line.260"></a>
-<span class="sourceLineNo">261</span>                     int[].class),<a name="line.261"></a>
-<span class="sourceLineNo">262</span>        /** Source of randomness is {@link Well19937c}. */<a name="line.262"></a>
-<span class="sourceLineNo">263</span>        WELL_19937_C(Well19937c.class,<a name="line.263"></a>
-<span class="sourceLineNo">264</span>                     int[].class),<a name="line.264"></a>
-<span class="sourceLineNo">265</span>        /** Source of randomness is {@link Well44497a}. */<a name="line.265"></a>
-<span class="sourceLineNo">266</span>        WELL_44497_A(Well44497a.class,<a name="line.266"></a>
-<span class="sourceLineNo">267</span>                     int[].class),<a name="line.267"></a>
-<span class="sourceLineNo">268</span>        /** Source of randomness is {@link Well44497b}. */<a name="line.268"></a>
-<span class="sourceLineNo">269</span>        WELL_44497_B(Well44497b.class,<a name="line.269"></a>
-<span class="sourceLineNo">270</span>                     int[].class),<a name="line.270"></a>
-<span class="sourceLineNo">271</span>        /** Source of randomness is {@link MersenneTwister}. */<a name="line.271"></a>
-<span class="sourceLineNo">272</span>        MT(MersenneTwister.class,<a name="line.272"></a>
-<span class="sourceLineNo">273</span>           int[].class),<a name="line.273"></a>
-<span class="sourceLineNo">274</span>        /** Source of randomness is {@link ISAACRandom}. */<a name="line.274"></a>
-<span class="sourceLineNo">275</span>        ISAAC(ISAACRandom.class,<a name="line.275"></a>
-<span class="sourceLineNo">276</span>              int[].class),<a name="line.276"></a>
-<span class="sourceLineNo">277</span>        /** Source of randomness is {@link SplitMix64}. */<a name="line.277"></a>
-<span class="sourceLineNo">278</span>        SPLIT_MIX_64(SplitMix64.class,<a name="line.278"></a>
-<span class="sourceLineNo">279</span>                     Long.class),<a name="line.279"></a>
-<span class="sourceLineNo">280</span>        /** Source of randomness is {@link XorShift1024Star}. */<a name="line.280"></a>
-<span class="sourceLineNo">281</span>        XOR_SHIFT_1024_S(XorShift1024Star.class,<a name="line.281"></a>
-<span class="sourceLineNo">282</span>                         long[].class),<a name="line.282"></a>
-<span class="sourceLineNo">283</span>        /** Source of randomness is {@link TwoCmres}. */<a name="line.283"></a>
-<span class="sourceLineNo">284</span>        TWO_CMRES(TwoCmres.class,<a name="line.284"></a>
-<span class="sourceLineNo">285</span>                  Integer.class),<a name="line.285"></a>
-<span class="sourceLineNo">286</span>        /**<a name="line.286"></a>
-<span class="sourceLineNo">287</span>         * Source of randomness is {@link TwoCmres} with explicit selection<a name="line.287"></a>
-<span class="sourceLineNo">288</span>         * of the two subcycle generators.<a name="line.288"></a>
-<span class="sourceLineNo">289</span>         */<a name="line.289"></a>
-<span class="sourceLineNo">290</span>        TWO_CMRES_SELECT(TwoCmres.class,<a name="line.290"></a>
-<span class="sourceLineNo">291</span>                         Integer.class,<a name="line.291"></a>
-<span class="sourceLineNo">292</span>                         Integer.TYPE,<a name="line.292"></a>
-<span class="sourceLineNo">293</span>                         Integer.TYPE),<a name="line.293"></a>
-<span class="sourceLineNo">294</span>        /** Source of randomness is {@link MersenneTwister64}. */<a name="line.294"></a>
-<span class="sourceLineNo">295</span>        MT_64(MersenneTwister64.class,<a name="line.295"></a>
-<span class="sourceLineNo">296</span>              long[].class);<a name="line.296"></a>
-<span class="sourceLineNo">297</span><a name="line.297"></a>
-<span class="sourceLineNo">298</span>        /** Source type. */<a name="line.298"></a>
-<span class="sourceLineNo">299</span>        private final Class&lt;? extends UniformRandomProvider&gt; rng;<a name="line.299"></a>
-<span class="sourceLineNo">300</span>        /** Data needed to build the generator. */<a name="line.300"></a>
-<span class="sourceLineNo">301</span>        private final Class&lt;?&gt;[] args;<a name="line.301"></a>
-<span class="sourceLineNo">302</span><a name="line.302"></a>
-<span class="sourceLineNo">303</span>        /**<a name="line.303"></a>
-<span class="sourceLineNo">304</span>         * @param rng Source type.<a name="line.304"></a>
-<span class="sourceLineNo">305</span>         * @param args Data needed to create a generator instance.<a name="line.305"></a>
-<span class="sourceLineNo">306</span>         * The first element must be the native seed type.<a name="line.306"></a>
-<span class="sourceLineNo">307</span>         */<a name="line.307"></a>
-<span class="sourceLineNo">308</span>        RandomSourceInternal(Class&lt;? extends UniformRandomProvider&gt; rng,<a name="line.308"></a>
-<span class="sourceLineNo">309</span>                             Class&lt;?&gt; ... args) {<a name="line.309"></a>
-<span class="sourceLineNo">310</span>            this.rng = rng;<a name="line.310"></a>
-<span class="sourceLineNo">311</span>            this.args = Arrays.copyOf(args, args.length);<a name="line.311"></a>
-<span class="sourceLineNo">312</span>        }<a name="line.312"></a>
-<span class="sourceLineNo">313</span><a name="line.313"></a>
-<span class="sourceLineNo">314</span>        /**<a name="line.314"></a>
-<span class="sourceLineNo">315</span>         * @return the source type.<a name="line.315"></a>
-<span class="sourceLineNo">316</span>         */<a name="line.316"></a>
-<span class="sourceLineNo">317</span>        public Class&lt;?&gt; getRng() {<a name="line.317"></a>
-<span class="sourceLineNo">318</span>            return rng;<a name="line.318"></a>
-<span class="sourceLineNo">319</span>        }<a name="line.319"></a>
-<span class="sourceLineNo">320</span><a name="line.320"></a>
-<span class="sourceLineNo">321</span>        /**<a name="line.321"></a>
-<span class="sourceLineNo">322</span>         * @return the seed type.<a name="line.322"></a>
-<span class="sourceLineNo">323</span>         */<a name="line.323"></a>
-<span class="sourceLineNo">324</span>        Class&lt;?&gt; getSeed() {<a name="line.324"></a>
-<span class="sourceLineNo">325</span>            return args[0];<a name="line.325"></a>
-<span class="sourceLineNo">326</span>        }<a name="line.326"></a>
-<span class="sourceLineNo">327</span><a name="line.327"></a>
-<span class="sourceLineNo">328</span>        /**<a name="line.328"></a>
-<span class="sourceLineNo">329</span>         * @return the data needed to build the generator.<a name="line.329"></a>
-<span class="sourceLineNo">330</span>         */<a name="line.330"></a>
-<span class="sourceLineNo">331</span>        Class&lt;?&gt;[] getArgs() {<a name="line.331"></a>
-<span class="sourceLineNo">332</span>            return args;<a name="line.332"></a>
-<span class="sourceLineNo">333</span>        }<a name="line.333"></a>
-<span class="sourceLineNo">334</span><a name="line.334"></a>
-<span class="sourceLineNo">335</span>        /**<a name="line.335"></a>
-<span class="sourceLineNo">336</span>         * Checks whether the type of given {@code seed} is the native type<a name="line.336"></a>
-<span class="sourceLineNo">337</span>         * of the implementation.<a name="line.337"></a>
-<span class="sourceLineNo">338</span>         *<a name="line.338"></a>
-<span class="sourceLineNo">339</span>         * @param &lt;SEED&gt; Seed type.<a name="line.339"></a>
-<span class="sourceLineNo">340</span>         *<a name="line.340"></a>
-<span class="sourceLineNo">341</span>         * @param seed Seed value.<a name="line.341"></a>
-<span class="sourceLineNo">342</span>         * @return {@code true} if the seed can be passed to the builder<a name="line.342"></a>
-<span class="sourceLineNo">343</span>         * for this RNG type.<a name="line.343"></a>
-<span class="sourceLineNo">344</span>         */<a name="line.344"></a>
-<span class="sourceLineNo">345</span>        public &lt;SEED&gt; boolean isNativeSeed(SEED seed) {<a name="line.345"></a>
-<span class="sourceLineNo">346</span>            return getSeed().equals(seed.getClass());<a name="line.346"></a>
-<span class="sourceLineNo">347</span>        }<a name="line.347"></a>
-<span class="sourceLineNo">348</span>    }<a name="line.348"></a>
-<span class="sourceLineNo">349</span>}<a name="line.349"></a>
+<span class="sourceLineNo">081</span>    private static final IntArray2Int INT_ARRAY_TO_INT = new IntArray2Int();<a name="line.81"></a>
+<span class="sourceLineNo">082</span>    /** Seed converter. */<a name="line.82"></a>
+<span class="sourceLineNo">083</span>    private static final LongArray2IntArray LONG_ARRAY_TO_INT_ARRAY = new LongArray2IntArray();<a name="line.83"></a>
+<span class="sourceLineNo">084</span>    /** Seed converter. */<a name="line.84"></a>
+<span class="sourceLineNo">085</span>    private static final IntArray2LongArray INT_ARRAY_TO_LONG_ARRAY = new IntArray2LongArray();<a name="line.85"></a>
+<span class="sourceLineNo">086</span>    /** Seed converter. */<a name="line.86"></a>
+<span class="sourceLineNo">087</span>    private static final ByteArray2IntArray BYTE_ARRAY_TO_INT_ARRAY = new ByteArray2IntArray();<a name="line.87"></a>
+<span class="sourceLineNo">088</span>    /** Seed converter. */<a name="line.88"></a>
+<span class="sourceLineNo">089</span>    private static final ByteArray2LongArray BYTE_ARRAY_TO_LONG_ARRAY = new ByteArray2LongArray();<a name="line.89"></a>
+<span class="sourceLineNo">090</span>    /** Map to convert "Integer" seeds. */<a name="line.90"></a>
+<span class="sourceLineNo">091</span>    private static final Map&lt;Class&lt;?&gt;, SeedConverter&lt;Integer,?&gt;&gt; CONV_INT =<a name="line.91"></a>
+<span class="sourceLineNo">092</span>        new HashMap&lt;Class&lt;?&gt;, SeedConverter&lt;Integer,?&gt;&gt;();<a name="line.92"></a>
+<span class="sourceLineNo">093</span>    /** Map to convert "int[]" seeds. */<a name="line.93"></a>
+<span class="sourceLineNo">094</span>    private static final Map&lt;Class&lt;?&gt;, SeedConverter&lt;int[],?&gt;&gt; CONV_INT_ARRAY =<a name="line.94"></a>
+<span class="sourceLineNo">095</span>        new HashMap&lt;Class&lt;?&gt;, SeedConverter&lt;int[],?&gt;&gt;();<a name="line.95"></a>
+<span class="sourceLineNo">096</span>    /** Map to convert "Long" seeds. */<a name="line.96"></a>
+<span class="sourceLineNo">097</span>    private static final Map&lt;Class&lt;?&gt;, SeedConverter&lt;Long,?&gt;&gt; CONV_LONG =<a name="line.97"></a>
+<span class="sourceLineNo">098</span>        new HashMap&lt;Class&lt;?&gt;, SeedConverter&lt;Long,?&gt;&gt;();<a name="line.98"></a>
+<span class="sourceLineNo">099</span>    /** Map to convert "long[]" seeds. */<a name="line.99"></a>
+<span class="sourceLineNo">100</span>    private static final Map&lt;Class&lt;?&gt;, SeedConverter&lt;long[],?&gt;&gt; CONV_LONG_ARRAY =<a name="line.100"></a>
+<span class="sourceLineNo">101</span>        new HashMap&lt;Class&lt;?&gt;, SeedConverter&lt;long[],?&gt;&gt;();<a name="line.101"></a>
+<span class="sourceLineNo">102</span>    /** Map to convert "byte[]" seeds. */<a name="line.102"></a>
+<span class="sourceLineNo">103</span>    private static final Map&lt;Class&lt;?&gt;, SeedConverter&lt;byte[],?&gt;&gt; CONV_BYTE_ARRAY =<a name="line.103"></a>
+<span class="sourceLineNo">104</span>        new HashMap&lt;Class&lt;?&gt;, SeedConverter&lt;byte[],?&gt;&gt;();<a name="line.104"></a>
+<span class="sourceLineNo">105</span><a name="line.105"></a>
+<span class="sourceLineNo">106</span>    static {<a name="line.106"></a>
+<span class="sourceLineNo">107</span>        // Input seed type is "Long".<a name="line.107"></a>
+<span class="sourceLineNo">108</span>        // Key is the implementation's "native" seed type.<a name="line.108"></a>
+<span class="sourceLineNo">109</span>        CONV_LONG.put(Integer.class, LONG_TO_INT);<a name="line.109"></a>
+<span class="sourceLineNo">110</span>        CONV_LONG.put(Long.class, new NoOpConverter&lt;Long&gt;());<a name="line.110"></a>
+<span class="sourceLineNo">111</span>        CONV_LONG.put(int[].class, LONG_TO_INT_ARRAY);<a name="line.111"></a>
+<span class="sourceLineNo">112</span>        CONV_LONG.put(long[].class, LONG_TO_LONG_ARRAY);<a name="line.112"></a>
+<span class="sourceLineNo">113</span><a name="line.113"></a>
+<span class="sourceLineNo">114</span>        // Input seed type is "Integer".<a name="line.114"></a>
+<span class="sourceLineNo">115</span>        // Key is the implementation's "native" seed type.<a name="line.115"></a>
+<span class="sourceLineNo">116</span>        CONV_INT.put(Integer.class, new NoOpConverter&lt;Integer&gt;());<a name="line.116"></a>
+<span class="sourceLineNo">117</span>        CONV_INT.put(Long.class, INT_TO_LONG);<a name="line.117"></a>
+<span class="sourceLineNo">118</span>        CONV_INT.put(int[].class, new SeedConverterComposer&lt;Integer,Long,int[]&gt;(INT_TO_LONG, LONG_TO_INT_ARRAY));<a name="line.118"></a>
+<span class="sourceLineNo">119</span>        CONV_INT.put(long[].class, new SeedConverterComposer&lt;Integer,Long,long[]&gt;(INT_TO_LONG, LONG_TO_LONG_ARRAY));<a name="line.119"></a>
+<span class="sourceLineNo">120</span><a name="line.120"></a>
+<span class="sourceLineNo">121</span>        // Input seed type is "int[]".<a name="line.121"></a>
+<span class="sourceLineNo">122</span>        // Key is the implementation's "native" seed type.<a name="line.122"></a>
+<span class="sourceLineNo">123</span>        CONV_INT_ARRAY.put(Integer.class, INT_ARRAY_TO_INT);<a name="line.123"></a>
+<span class="sourceLineNo">124</span>        CONV_INT_ARRAY.put(Long.class, new SeedConverterComposer&lt;int[],Integer,Long&gt;(INT_ARRAY_TO_INT, INT_TO_LONG));<a name="line.124"></a>
+<span class="sourceLineNo">125</span>        CONV_INT_ARRAY.put(int[].class, new NoOpConverter&lt;int[]&gt;());<a name="line.125"></a>
+<span class="sourceLineNo">126</span>        CONV_INT_ARRAY.put(long[].class, INT_ARRAY_TO_LONG_ARRAY);<a name="line.126"></a>
+<span class="sourceLineNo">127</span><a name="line.127"></a>
+<span class="sourceLineNo">128</span>        // Input seed type is "long[]".<a name="line.128"></a>
+<span class="sourceLineNo">129</span>        // Key is the implementation's "native" seed type.<a name="line.129"></a>
+<span class="sourceLineNo">130</span>        CONV_LONG_ARRAY.put(Integer.class, new SeedConverterComposer&lt;long[],Long,Integer&gt;(LONG_ARRAY_TO_LONG, LONG_TO_INT));<a name="line.130"></a>
+<span class="sourceLineNo">131</span>        CONV_LONG_ARRAY.put(Long.class, LONG_ARRAY_TO_LONG);<a name="line.131"></a>
+<span class="sourceLineNo">132</span>        CONV_LONG_ARRAY.put(int[].class, LONG_ARRAY_TO_INT_ARRAY);<a name="line.132"></a>
+<span class="sourceLineNo">133</span>        CONV_LONG_ARRAY.put(long[].class, new NoOpConverter&lt;long[]&gt;());<a name="line.133"></a>
+<span class="sourceLineNo">134</span><a name="line.134"></a>
+<span class="sourceLineNo">135</span>        // Input seed type is "byte[]".<a name="line.135"></a>
+<span class="sourceLineNo">136</span>        // Key is the implementation's "native" seed type.<a name="line.136"></a>
+<span class="sourceLineNo">137</span>        CONV_BYTE_ARRAY.put(Integer.class, new SeedConverterComposer&lt;byte[],int[],Integer&gt;(BYTE_ARRAY_TO_INT_ARRAY, INT_ARRAY_TO_INT));<a name="line.137"></a>
+<span class="sourceLineNo">138</span>        CONV_BYTE_ARRAY.put(Long.class, new SeedConverterComposer&lt;byte[],long[],Long&gt;(BYTE_ARRAY_TO_LONG_ARRAY, LONG_ARRAY_TO_LONG));<a name="line.138"></a>
+<span class="sourceLineNo">139</span>        CONV_BYTE_ARRAY.put(int[].class, BYTE_ARRAY_TO_INT_ARRAY);<a name="line.139"></a>
+<span class="sourceLineNo">140</span>        CONV_BYTE_ARRAY.put(long[].class, BYTE_ARRAY_TO_LONG_ARRAY);<a name="line.140"></a>
+<span class="sourceLineNo">141</span>    }<a name="line.141"></a>
+<span class="sourceLineNo">142</span><a name="line.142"></a>
+<span class="sourceLineNo">143</span>    /**<a name="line.143"></a>
+<span class="sourceLineNo">144</span>     * Class only contains static method.<a name="line.144"></a>
+<span class="sourceLineNo">145</span>     */<a name="line.145"></a>
+<span class="sourceLineNo">146</span>    private ProviderBuilder() {}<a name="line.146"></a>
+<span class="sourceLineNo">147</span><a name="line.147"></a>
+<span class="sourceLineNo">148</span>    /**<a name="line.148"></a>
+<span class="sourceLineNo">149</span>     * Creates a RNG instance.<a name="line.149"></a>
+<span class="sourceLineNo">150</span>     *<a name="line.150"></a>
+<span class="sourceLineNo">151</span>     * @param source RNG specification.<a name="line.151"></a>
+<span class="sourceLineNo">152</span>     * @param seed Seed value.  It can be {@code null} (in which case a<a name="line.152"></a>
+<span class="sourceLineNo">153</span>     * random value will be used).<a name="line.153"></a>
+<span class="sourceLineNo">154</span>     * @param args Additional arguments to the implementation's constructor.<a name="line.154"></a>
+<span class="sourceLineNo">155</span>     * @return a new RNG instance.<a name="line.155"></a>
+<span class="sourceLineNo">156</span>     * @throws UnsupportedOperationException if the seed type is invalid.<a name="line.156"></a>
+<span class="sourceLineNo">157</span>     */<a name="line.157"></a>
+<span class="sourceLineNo">158</span>    public static UniformRandomProvider create(RandomSourceInternal source,<a name="line.158"></a>
+<span class="sourceLineNo">159</span>                                               Object seed,<a name="line.159"></a>
+<span class="sourceLineNo">160</span>                                               Object[] args) {<a name="line.160"></a>
+<span class="sourceLineNo">161</span>        // Convert seed to native type.<a name="line.161"></a>
+<span class="sourceLineNo">162</span>        final Object nativeSeed = createSeed(source, seed);<a name="line.162"></a>
+<span class="sourceLineNo">163</span><a name="line.163"></a>
+<span class="sourceLineNo">164</span>        // Build a single array with all the arguments to be passed<a name="line.164"></a>
+<span class="sourceLineNo">165</span>        // (in the right order) to the constructor.<a name="line.165"></a>
+<span class="sourceLineNo">166</span>        final List&lt;Object&gt; all = new ArrayList&lt;Object&gt;();<a name="line.166"></a>
+<span class="sourceLineNo">167</span>        all.add(nativeSeed);<a name="line.167"></a>
+<span class="sourceLineNo">168</span>        if (args != null) {<a name="line.168"></a>
+<span class="sourceLineNo">169</span>            all.addAll(Arrays.asList(args));<a name="line.169"></a>
+<span class="sourceLineNo">170</span>        }<a name="line.170"></a>
+<span class="sourceLineNo">171</span><a name="line.171"></a>
+<span class="sourceLineNo">172</span>        // Instantiate.<a name="line.172"></a>
+<span class="sourceLineNo">173</span>        return create(createConstructor(source), all.toArray());<a name="line.173"></a>
+<span class="sourceLineNo">174</span>    }<a name="line.174"></a>
+<span class="sourceLineNo">175</span><a name="line.175"></a>
+<span class="sourceLineNo">176</span>    /**<a name="line.176"></a>
+<span class="sourceLineNo">177</span>     * Creates a native seed from any of the supported seed types.<a name="line.177"></a>
+<span class="sourceLineNo">178</span>     *<a name="line.178"></a>
+<span class="sourceLineNo">179</span>     * @param source Source.<a name="line.179"></a>
+<span class="sourceLineNo">180</span>     * @param seed Input seed.<a name="line.180"></a>
+<span class="sourceLineNo">181</span>     * @return the native seed.<a name="line.181"></a>
+<span class="sourceLineNo">182</span>     * @throw UnsupportedOperationException if the {@code seed} type is invalid.<a name="line.182"></a>
+<span class="sourceLineNo">183</span>     */<a name="line.183"></a>
+<span class="sourceLineNo">184</span>    private static Object createSeed(RandomSourceInternal source,<a name="line.184"></a>
+<span class="sourceLineNo">185</span>                                     Object seed) {<a name="line.185"></a>
+<span class="sourceLineNo">186</span>        Object nativeSeed = null;<a name="line.186"></a>
+<span class="sourceLineNo">187</span><a name="line.187"></a>
+<span class="sourceLineNo">188</span>        if (seed == null) {<a name="line.188"></a>
+<span class="sourceLineNo">189</span>            // Create a random seed of the appropriate native type.<a name="line.189"></a>
+<span class="sourceLineNo">190</span><a name="line.190"></a>
+<span class="sourceLineNo">191</span>            if (source.getSeed().equals(Integer.class)) {<a name="line.191"></a>
+<span class="sourceLineNo">192</span>                nativeSeed = SeedFactory.createInt();<a name="line.192"></a>
+<span class="sourceLineNo">193</span>            } else if (source.getSeed().equals(Long.class)) {<a name="line.193"></a>
+<span class="sourceLineNo">194</span>                nativeSeed = SeedFactory.createLong();<a name="line.194"></a>
+<span class="sourceLineNo">195</span>            } else if (source.getSeed().equals(int[].class)) {<a name="line.195"></a>
+<span class="sourceLineNo">196</span>                nativeSeed = SeedFactory.createIntArray(RANDOM_SEED_ARRAY_SIZE);<a name="line.196"></a>
+<span class="sourceLineNo">197</span>            } else if (source.getSeed().equals(long[].class)) {<a name="line.197"></a>
+<span class="sourceLineNo">198</span>                nativeSeed = SeedFactory.createLongArray(RANDOM_SEED_ARRAY_SIZE);<a name="line.198"></a>
+<span class="sourceLineNo">199</span>            } else {<a name="line.199"></a>
+<span class="sourceLineNo">200</span>                // Source's native type is not handled.<a name="line.200"></a>
+<span class="sourceLineNo">201</span>                throw new IllegalStateException(INTERNAL_ERROR_MSG);<a name="line.201"></a>
+<span class="sourceLineNo">202</span>            }<a name="line.202"></a>
+<span class="sourceLineNo">203</span>        } else {<a name="line.203"></a>
+<span class="sourceLineNo">204</span>            // Convert to native type.<a name="line.204"></a>
+<span class="sourceLineNo">205</span><a name="line.205"></a>
+<span class="sourceLineNo">206</span>            if (seed instanceof Integer) {<a name="line.206"></a>
+<span class="sourceLineNo">207</span>                nativeSeed = CONV_INT.get(source.getSeed()).convert((Integer) seed);<a name="line.207"></a>
+<span class="sourceLineNo">208</span>            } else if (seed instanceof Long) {<a name="line.208"></a>
+<span class="sourceLineNo">209</span>                nativeSeed = CONV_LONG.get(source.getSeed()).convert((Long) seed);<a name="line.209"></a>
+<span class="sourceLineNo">210</span>            } else if (seed instanceof int[]) {<a name="line.210"></a>
+<span class="sourceLineNo">211</span>                nativeSeed = CONV_INT_ARRAY.get(source.getSeed()).convert((int[]) seed);<a name="line.211"></a>
+<span class="sourceLineNo">212</span>            } else if (seed instanceof long[]) {<a name="line.212"></a>
+<span class="sourceLineNo">213</span>                nativeSeed = CONV_LONG_ARRAY.get(source.getSeed()).convert((long[]) seed);<a name="line.213"></a>
+<span class="sourceLineNo">214</span>            } else if (seed instanceof byte[]) {<a name="line.214"></a>
+<span class="sourceLineNo">215</span>                nativeSeed = CONV_BYTE_ARRAY.get(source.getSeed()).convert((byte[]) seed);<a name="line.215"></a>
+<span class="sourceLineNo">216</span>            }<a name="line.216"></a>
+<span class="sourceLineNo">217</span><a name="line.217"></a>
+<span class="sourceLineNo">218</span>            if (nativeSeed == null) {<a name="line.218"></a>
+<span class="sourceLineNo">219</span>                // Since the input seed was not null, getting here means that<a name="line.219"></a>
+<span class="sourceLineNo">220</span>                // no suitable converter is present in the maps.<a name="line.220"></a>
+<span class="sourceLineNo">221</span>                throw new UnsupportedOperationException("Unrecognized seed type");<a name="line.221"></a>
+<span class="sourceLineNo">222</span>            }<a name="line.222"></a>
+<span class="sourceLineNo">223</span><a name="line.223"></a>
+<span class="sourceLineNo">224</span>            if (!source.isNativeSeed(nativeSeed)) {<a name="line.224"></a>
+<span class="sourceLineNo">225</span>                // Conversion setup is wrong.<a name="line.225"></a>
+<span class="sourceLineNo">226</span>                throw new IllegalStateException(INTERNAL_ERROR_MSG);<a name="line.226"></a>
+<span class="sourceLineNo">227</span>            }<a name="line.227"></a>
+<span class="sourceLineNo">228</span>        }<a name="line.228"></a>
+<span class="sourceLineNo">229</span><a name="line.229"></a>
+<span class="sourceLineNo">230</span>        return nativeSeed;<a name="line.230"></a>
+<span class="sourceLineNo">231</span>    }<a name="line.231"></a>
+<span class="sourceLineNo">232</span><a name="line.232"></a>
+<span class="sourceLineNo">233</span>    /**<a name="line.233"></a>
+<span class="sourceLineNo">234</span>     * Creates a constructor.<a name="line.234"></a>
+<span class="sourceLineNo">235</span>     *<a name="line.235"></a>
+<span class="sourceLineNo">236</span>     * @param source RNG specification.<a name="line.236"></a>
+<span class="sourceLineNo">237</span>     * @return a RNG constructor.<a name="line.237"></a>
+<span class="sourceLineNo">238</span>     */<a name="line.238"></a>
+<span class="sourceLineNo">239</span>    private static Constructor&lt;?&gt; createConstructor(RandomSourceInternal source) {<a name="line.239"></a>
+<span class="sourceLineNo">240</span>        try {<a name="line.240"></a>
+<span class="sourceLineNo">241</span>            return source.getRng().getConstructor(source.getArgs());<a name="line.241"></a>
+<span class="sourceLineNo">242</span>        } catch (NoSuchMethodException e) {<a name="line.242"></a>
+<span class="sourceLineNo">243</span>            // Info in "RandomSourceInternal" is inconsistent with the<a name="line.243"></a>
+<span class="sourceLineNo">244</span>            // constructor of the implementation.<a name="line.244"></a>
+<span class="sourceLineNo">245</span>            throw new IllegalStateException(INTERNAL_ERROR_MSG, e);<a name="line.245"></a>
+<span class="sourceLineNo">246</span>        }<a name="line.246"></a>
+<span class="sourceLineNo">247</span>    }<a name="line.247"></a>
+<span class="sourceLineNo">248</span><a name="line.248"></a>
+<span class="sourceLineNo">249</span>    /**<a name="line.249"></a>
+<span class="sourceLineNo">250</span>     * Creates a RNG.<a name="line.250"></a>
+<span class="sourceLineNo">251</span>     *<a name="line.251"></a>
+<span class="sourceLineNo">252</span>     * @param rng RNG specification.<a name="line.252"></a>
+<span class="sourceLineNo">253</span>     * @param args Arguments to the implementation's constructor.<a name="line.253"></a>
+<span class="sourceLineNo">254</span>     * @return a new RNG instance.<a name="line.254"></a>
+<span class="sourceLineNo">255</span>     */<a name="line.255"></a>
+<span class="sourceLineNo">256</span>    private static UniformRandomProvider create(Constructor&lt;?&gt; rng,<a name="line.256"></a>
+<span class="sourceLineNo">257</span>                                                Object[] args) {<a name="line.257"></a>
+<span class="sourceLineNo">258</span>        try {<a name="line.258"></a>
+<span class="sourceLineNo">259</span>            return (UniformRandomProvider) rng.newInstance(args);<a name="line.259"></a>
+<span class="sourceLineNo">260</span>        } catch (InvocationTargetException e) {<a name="line.260"></a>
+<span class="sourceLineNo">261</span>            throw new IllegalStateException(INTERNAL_ERROR_MSG, e);<a name="line.261"></a>
+<span class="sourceLineNo">262</span>        } catch (InstantiationException e) {<a name="line.262"></a>
+<span class="sourceLineNo">263</span>            throw new IllegalStateException(INTERNAL_ERROR_MSG, e);<a name="line.263"></a>
+<span class="sourceLineNo">264</span>        } catch (IllegalAccessException e) {<a name="line.264"></a>
+<span class="sourceLineNo">265</span>            throw new IllegalStateException(INTERNAL_ERROR_MSG, e);<a name="line.265"></a>
+<span class="sourceLineNo">266</span>        }<a name="line.266"></a>
+<span class="sourceLineNo">267</span>    }<a name="line.267"></a>
+<span class="sourceLineNo">268</span><a name="line.268"></a>
+<span class="sourceLineNo">269</span>    /**<a name="line.269"></a>
+<span class="sourceLineNo">270</span>     * Identifiers of the generators.<a name="line.270"></a>
+<span class="sourceLineNo">271</span>     */<a name="line.271"></a>
+<span class="sourceLineNo">272</span>    public enum RandomSourceInternal {<a name="line.272"></a>
+<span class="sourceLineNo">273</span>        /** Source of randomness is {@link JDKRandom}. */<a name="line.273"></a>
+<span class="sourceLineNo">274</span>        JDK(JDKRandom.class,<a name="line.274"></a>
+<span class="sourceLineNo">275</span>            Long.class),<a name="line.275"></a>
+<span class="sourceLineNo">276</span>        /** Source of randomness is {@link Well512a}. */<a name="line.276"></a>
+<span class="sourceLineNo">277</span>        WELL_512_A(Well512a.class,<a name="line.277"></a>
+<span class="sourceLineNo">278</span>                   int[].class),<a name="line.278"></a>
+<span class="sourceLineNo">279</span>        /** Source of randomness is {@link Well1024a}. */<a name="line.279"></a>
+<span class="sourceLineNo">280</span>        WELL_1024_A(Well1024a.class,<a name="line.280"></a>
+<span class="sourceLineNo">281</span>                    int[].class),<a name="line.281"></a>
+<span class="sourceLineNo">282</span>        /** Source of randomness is {@link Well19937a}. */<a name="line.282"></a>
+<span class="sourceLineNo">283</span>        WELL_19937_A(Well19937a.class,<a name="line.283"></a>
+<span class="sourceLineNo">284</span>                     int[].class),<a name="line.284"></a>
+<span class="sourceLineNo">285</span>        /** Source of randomness is {@link Well19937c}. */<a name="line.285"></a>
+<span class="sourceLineNo">286</span>        WELL_19937_C(Well19937c.class,<a name="line.286"></a>
+<span class="sourceLineNo">287</span>                     int[].class),<a name="line.287"></a>
+<span class="sourceLineNo">288</span>        /** Source of randomness is {@link Well44497a}. */<a name="line.288"></a>
+<span class="sourceLineNo">289</span>        WELL_44497_A(Well44497a.class,<a name="line.289"></a>
+<span class="sourceLineNo">290</span>                     int[].class),<a name="line.290"></a>
+<span class="sourceLineNo">291</span>        /** Source of randomness is {@link Well44497b}. */<a name="line.291"></a>
+<span class="sourceLineNo">292</span>        WELL_44497_B(Well44497b.class,<a name="line.292"></a>
+<span class="sourceLineNo">293</span>                     int[].class),<a name="line.293"></a>
+<span class="sourceLineNo">294</span>        /** Source of randomness is {@link MersenneTwister}. */<a name="line.294"></a>
+<span class="sourceLineNo">295</span>        MT(MersenneTwister.class,<a name="line.295"></a>
+<span class="sourceLineNo">296</span>           int[].class),<a name="line.296"></a>
+<span class="sourceLineNo">297</span>        /** Source of randomness is {@link ISAACRandom}. */<a name="line.297"></a>
+<span class="sourceLineNo">298</span>        ISAAC(ISAACRandom.class,<a name="line.298"></a>
+<span class="sourceLineNo">299</span>              int[].class),<a name="line.299"></a>
+<span class="sourceLineNo">300</span>        /** Source of randomness is {@link SplitMix64}. */<a name="line.300"></a>
+<span class="sourceLineNo">301</span>        SPLIT_MIX_64(SplitMix64.class,<a name="line.301"></a>
+<span class="sourceLineNo">302</span>                     Long.class),<a name="line.302"></a>
+<span class="sourceLineNo">303</span>        /** Source of randomness is {@link XorShift1024Star}. */<a name="line.303"></a>
+<span class="sourceLineNo">304</span>        XOR_SHIFT_1024_S(XorShift1024Star.class,<a name="line.304"></a>
+<span class="sourceLineNo">305</span>                         long[].class),<a name="line.305"></a>
+<span class="sourceLineNo">306</span>        /** Source of randomness is {@link TwoCmres}. */<a name="line.306"></a>
+<span class="sourceLineNo">307</span>        TWO_CMRES(TwoCmres.class,<a name="line.307"></a>
+<span class="sourceLineNo">308</span>                  Integer.class),<a name="line.308"></a>
+<span class="sourceLineNo">309</span>        /**<a name="line.309"></a>
+<span class="sourceLineNo">310</span>         * Source of randomness is {@link TwoCmres} with explicit selection<a name="line.310"></a>
+<span class="sourceLineNo">311</span>         * of the two subcycle generators.<a name="line.311"></a>
+<span class="sourceLineNo">312</span>         */<a name="line.312"></a>
+<span class="sourceLineNo">313</span>        TWO_CMRES_SELECT(TwoCmres.class,<a name="line.313"></a>
+<span class="sourceLineNo">314</span>                         Integer.class,<a name="line.314"></a>
+<span class="sourceLineNo">315</span>                         Integer.TYPE,<a name="line.315"></a>
+<span class="sourceLineNo">316</span>                         Integer.TYPE),<a name="line.316"></a>
+<span class="sourceLineNo">317</span>        /** Source of randomness is {@link MersenneTwister64}. */<a name="line.317"></a>
+<span class="sourceLineNo">318</span>        MT_64(MersenneTwister64.class,<a name="line.318"></a>
+<span class="sourceLineNo">319</span>              long[].class),<a name="line.319"></a>
+<span class="sourceLineNo">320</span>        /** Source of randomness is {@link MultiplyWithCarry256}. */<a name="line.320"></a>
+<span class="sourceLineNo">321</span>        MWC_256(MultiplyWithCarry256.class,<a name="line.321"></a>
+<span class="sourceLineNo">322</span>                int[].class),<a name="line.322"></a>
+<span class="sourceLineNo">323</span>        /** Source of randomness is {@link KISSRandom}. */<a name="line.323"></a>
+<span class="sourceLineNo">324</span>        KISS(KISSRandom.class,<a name="line.324"></a>
+<span class="sourceLineNo">325</span>             int[].class);<a name="line.325"></a>
+<span class="sourceLineNo">326</span><a name="line.326"></a>
+<span class="sourceLineNo">327</span>        /** Source type. */<a name="line.327"></a>
+<span class="sourceLineNo">328</span>        private final Class&lt;? extends UniformRandomProvider&gt; rng;<a name="line.328"></a>
+<span class="sourceLineNo">329</span>        /** Data needed to build the generator. */<a name="line.329"></a>
+<span class="sourceLineNo">330</span>        private final Class&lt;?&gt;[] args;<a name="line.330"></a>
+<span class="sourceLineNo">331</span><a name="line.331"></a>
+<span class="sourceLineNo">332</span>        /**<a name="line.332"></a>
+<span class="sourceLineNo">333</span>         * @param rng Source type.<a name="line.333"></a>
+<span class="sourceLineNo">334</span>         * @param args Data needed to create a generator instance.<a name="line.334"></a>
+<span class="sourceLineNo">335</span>         * The first element must be the native seed type.<a name="line.335"></a>
+<span class="sourceLineNo">336</span>         */<a name="line.336"></a>
+<span class="sourceLineNo">337</span>        RandomSourceInternal(Class&lt;? extends UniformRandomProvider&gt; rng,<a name="line.337"></a>
+<span class="sourceLineNo">338</span>                             Class&lt;?&gt; ... args) {<a name="line.338"></a>
+<span class="sourceLineNo">339</span>            this.rng = rng;<a name="line.339"></a>
+<span class="sourceLineNo">340</span>            this.args = Arrays.copyOf(args, args.length);<a name="line.340"></a>
+<span class="sourceLineNo">341</span>        }<a name="line.341"></a>
+<span class="sourceLineNo">342</span><a name="line.342"></a>
+<span class="sourceLineNo">343</span>        /**<a name="line.343"></a>
+<span class="sourceLineNo">344</span>         * @return the source type.<a name="line.344"></a>
+<span class="sourceLineNo">345</span>         */<a name="line.345"></a>
+<span class="sourceLineNo">346</span>        public Class&lt;?&gt; getRng() {<a name="line.346"></a>
+<span class="sourceLineNo">347</span>            return rng;<a name="line.347"></a>
+<span class="sourceLineNo">348</span>        }<a name="line.348"></a>
+<span class="sourceLineNo">349</span><a name="line.349"></a>
+<span class="sourceLineNo">350</span>        /**<a name="line.350"></a>
+<span class="sourceLineNo">351</span>         * @return the seed type.<a name="line.351"></a>
+<span class="sourceLineNo">352</span>         */<a name="line.352"></a>
+<span class="sourceLineNo">353</span>        Class&lt;?&gt; getSeed() {<a name="line.353"></a>
+<span class="sourceLineNo">354</span>            return args[0];<a name="line.354"></a>
+<span class="sourceLineNo">355</span>        }<a name="line.355"></a>
+<span class="sourceLineNo">356</span><a name="line.356"></a>
+<span class="sourceLineNo">357</span>        /**<a name="line.357"></a>
+<span class="sourceLineNo">358</span>         * @return the data needed to build the generator.<a name="line.358"></a>
+<span class="sourceLineNo">359</span>         */<a name="line.359"></a>
+<span class="sourceLineNo">360</span>        Class&lt;?&gt;[] getArgs() {<a name="line.360"></a>
+<span class="sourceLineNo">361</span>            return args;<a name="line.361"></a>
+<span class="sourceLineNo">362</span>        }<a name="line.362"></a>
+<span class="sourceLineNo">363</span><a name="line.363"></a>
+<span class="sourceLineNo">364</span>        /**<a name="line.364"></a>
+<span class="sourceLineNo">365</span>         * Checks whether the type of given {@code seed} is the native type<a name="line.365"></a>
+<span class="sourceLineNo">366</span>         * of the implementation.<a name="line.366"></a>
+<span class="sourceLineNo">367</span>         *<a name="line.367"></a>
+<span class="sourceLineNo">368</span>         * @param &lt;SEED&gt; Seed type.<a name="line.368"></a>
+<span class="sourceLineNo">369</span>         *<a name="line.369"></a>
+<span class="sourceLineNo">370</span>         * @param seed Seed value.<a name="line.370"></a>
+<span class="sourceLineNo">371</span>         * @return {@code true} if the seed can be passed to the builder<a name="line.371"></a>
+<span class="sourceLineNo">372</span>         * for this RNG type.<a name="line.372"></a>
+<span class="sourceLineNo">373</span>         */<a name="line.373"></a>
+<span class="sourceLineNo">374</span>        public &lt;SEED&gt; boolean isNativeSeed(SEED seed) {<a name="line.374"></a>
+<span class="sourceLineNo">375</span>            return seed == null ?<a name="line.375"></a>
+<span class="sourceLineNo">376</span>                false :<a name="line.376"></a>
+<span class="sourceLineNo">377</span>                getSeed().equals(seed.getClass());<a name="line.377"></a>
+<span class="sourceLineNo">378</span>        }<a name="line.378"></a>
+<span class="sourceLineNo">379</span>    }<a name="line.379"></a>
+<span class="sourceLineNo">380</span>}<a name="line.380"></a>
 
 
 



Mime
View raw message