| 
001 /*002  * Java Genetic Algorithm Library (jenetics-3.0.0).
 003  * Copyright (c) 2007-2014 Franz Wilhelmstötter
 004  *
 005  * Licensed under the Apache License, Version 2.0 (the "License");
 006  * you may not use this file except in compliance with the License.
 007  * You may obtain a copy of the License at
 008  *
 009  *      http://www.apache.org/licenses/LICENSE-2.0
 010  *
 011  * Unless required by applicable law or agreed to in writing, software
 012  * distributed under the License is distributed on an "AS IS" BASIS,
 013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 014  * See the License for the specific language governing permissions and
 015  * limitations under the License.
 016  *
 017  * Author:
 018  *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
 019  */
 020 package org.jenetics.util;
 021
 022 import java.util.Random;
 023
 024 import org.jenetics.internal.math.random;
 025
 026 /**
 027  * Abstract {@code Random} class with additional <i>next</i> random number
 028  * methods.
 029  *
 030  * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
 031  * @since 1.2
 032  * @version 2.0 — <em>$Date: 2014-12-28 $</em>
 033  */
 034 abstract class PRNG extends Random {
 035
 036     private static final long serialVersionUID = 1L;
 037
 038     /**
 039      * Create a new {@code PRNG} instance with the given {@code seed}.
 040      *
 041      * @param seed the seed of the new {@code PRNG} instance.
 042      */
 043     protected PRNG(final long seed) {
 044         super(seed);
 045     }
 046
 047     /**
 048      * Create a new {@code PRNG} instance with a seed created with the
 049      * {@link org.jenetics.internal.math.random#seed()} value.
 050      */
 051     protected PRNG() {
 052         this(random.seed());
 053     }
 054
 055     /**
 056      * Returns a pseudorandom, uniformly distributed int value between min and
 057      * max (end points included).
 058      *
 059      * @param min lower bound for generated integer (inclusively)
 060      * @param max upper bound for generated integer (inclusively)
 061      * @return a random integer greater than or equal to {@code min} and less
 062      *         than or equal to {@code max}
 063      * @throws IllegalArgumentException if {@code min >= max}
 064      *
 065      * @see org.jenetics.internal.math.random#nextInt(java.util.Random, int, int)
 066      */
 067     public int nextInt(final int min, final int max) {
 068         return random.nextInt(this, min, max);
 069     }
 070
 071     /**
 072      * Returns a pseudorandom, uniformly distributed int value between min
 073      * and max (end points included).
 074      *
 075      * @param min lower bound for generated long integer (inclusively)
 076      * @param max upper bound for generated long integer (inclusively)
 077      * @return a random long integer greater than or equal to {@code min}
 078      *         and less than or equal to {@code max}
 079      * @throws IllegalArgumentException if {@code min >= max}
 080      *
 081      * @see org.jenetics.internal.math.random#nextLong(java.util.Random, long, long)
 082      */
 083     public long nextLong(final long min, final long max) {
 084         return random.nextLong(this, min, max);
 085     }
 086
 087     /**
 088      * Returns a pseudorandom, uniformly distributed int value between 0
 089      * (inclusive) and the specified value (exclusive), drawn from the given
 090      * random number generator's sequence.
 091      *
 092      * @param n the bound on the random number to be returned. Must be
 093      *        positive.
 094      * @return the next pseudorandom, uniformly distributed int value
 095      *         between 0 (inclusive) and n (exclusive) from the given random
 096      *         number generator's sequence
 097      * @throws IllegalArgumentException if n is smaller than 1.
 098      *
 099      * @see org.jenetics.internal.math.random#nextLong(java.util.Random, long)
 100      */
 101     public long nextLong(final long n) {
 102         return random.nextLong(this, n);
 103     }
 104
 105     /**
 106      * Returns a pseudorandom, uniformly distributed double value between
 107      * min (inclusively) and max (exclusively).
 108      *
 109      * @param min lower bound for generated float value (inclusively)
 110      * @param max upper bound for generated float value (exclusively)
 111      * @return a random float greater than or equal to {@code min} and less
 112      *         than to {@code max}
 113      *
 114      * @see org.jenetics.internal.math.random#nextFloat(java.util.Random, float, float)
 115      */
 116     public float nextFloat(final float min, final float max) {
 117         return random.nextFloat(this, min, max);
 118     }
 119
 120     /**
 121      * Returns a pseudorandom, uniformly distributed double value between
 122      * min (inclusively) and max (exclusively).
 123      *
 124      * @param min lower bound for generated double value (inclusively)
 125      * @param max upper bound for generated double value (exclusively)
 126      * @return a random double greater than or equal to {@code min} and less
 127      *         than to {@code max}
 128      *
 129      * @see org.jenetics.internal.math.random#nextDouble(java.util.Random, double, double)
 130      */
 131     public double nextDouble(final double min, final double max) {
 132         return random.nextDouble(this, min, max);
 133     }
 134
 135 }
 |