SamplerBase.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.rng.sampling.distribution;

  18. import org.apache.commons.rng.UniformRandomProvider;

  19. /**
  20.  * Base class for a sampler.
  21.  *
  22.  * @since 1.0
  23.  *
  24.  * @deprecated Since version 1.1. Class intended for internal use only.
  25.  */
  26. @Deprecated
  27. public class SamplerBase {
  28.     /** RNG. */
  29.     private final UniformRandomProvider rng;

  30.     /**
  31.      * Create an instance.
  32.      *
  33.      * @param rng Generator of uniformly distributed random numbers.
  34.      */
  35.     protected SamplerBase(UniformRandomProvider rng) {
  36.         this.rng = rng;
  37.     }

  38.     /**
  39.      * Return the next {@code double} value.
  40.      *
  41.      * @return a random value from a uniform distribution in the
  42.      * interval {@code [0, 1)}.
  43.      */
  44.     protected double nextDouble() {
  45.         return rng.nextDouble();
  46.     }

  47.     /**
  48.      * Return the next {@code int} value.
  49.      *
  50.      * @return a random {@code int} value.
  51.      */
  52.     protected int nextInt() {
  53.         return rng.nextInt();
  54.     }

  55.     /**
  56.      * Return the next {@code int} value.
  57.      *
  58.      * @param max Upper bound (excluded).
  59.      * @return a random {@code int} value in the interval {@code [0, max)}.
  60.      */
  61.     protected int nextInt(int max) {
  62.         return rng.nextInt(max);
  63.     }

  64.     /**
  65.      * Return the next {@code long} value.
  66.      *
  67.      * @return a random {@code long} value.
  68.      */
  69.     protected long nextLong() {
  70.         return rng.nextLong();
  71.     }

  72.     /** {@inheritDoc} */
  73.     @Override
  74.     public String toString() {
  75.         return "rng=" + rng.toString();
  76.     }
  77. }