| 1 | package de.uka.ipd.sdq.probfunction.math.apache.impl; |
| 2 | |
| 3 | |
| 4 | import org.apache.commons.math.random.RandomGenerator; |
| 5 | import de.uka.ipd.sdq.probfunction.math.random.IRandomStream; |
| 6 | |
| 7 | |
| 8 | /** |
| 9 | * Adapter for apache.math random generators. |
| 10 | * |
| 11 | * @author joerg |
| 12 | * |
| 13 | */ |
| 14 | public class ApacheMathRandomGenerator implements IRandomStream |
| 15 | { |
| 16 | |
| 17 | protected RandomGenerator rng; |
| 18 | |
| 19 | public ApacheMathRandomGenerator(RandomGenerator rng) { |
| 20 | super(); |
| 21 | this.rng = rng; |
| 22 | } |
| 23 | |
| 24 | @Override |
| 25 | public void setSeed(int[] seed) { |
| 26 | rng.setSeed(seed); |
| 27 | } |
| 28 | |
| 29 | @Override |
| 30 | public double nextDouble() { |
| 31 | return rng.nextDouble(); |
| 32 | } |
| 33 | |
| 34 | @Override |
| 35 | public void setSeed(long[] seed) { |
| 36 | int[] intSeed = new int[seed.length]; |
| 37 | |
| 38 | for(int i=0;i<seed.length;i++) |
| 39 | { |
| 40 | long s = seed[i]; |
| 41 | if (s < Integer.MIN_VALUE || s > Integer.MAX_VALUE) { |
| 42 | throw new IllegalArgumentException |
| 43 | (s + " cannot be cast to int without changing its value."); |
| 44 | } |
| 45 | intSeed[i] = (int)s; |
| 46 | } |
| 47 | setSeed(intSeed); |
| 48 | } |
| 49 | |
| 50 | } |