View Javadoc
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  
19  import org.apache.commons.rng.UniformRandomProvider;
20  
21  /**
22   * Base class for a sampler.
23   *
24   * @since 1.0
25   *
26   * @deprecated Since version 1.1. Class intended for internal use only.
27   */
28  @Deprecated
29  public class SamplerBase {
30      /** RNG. */
31      private final UniformRandomProvider rng;
32  
33      /**
34       * @param rng Generator of uniformly distributed random numbers.
35       */
36      protected SamplerBase(UniformRandomProvider rng) {
37          this.rng = rng;
38      }
39  
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      /**
49       * @return a random {@code int} value.
50       */
51      protected int nextInt() {
52          return rng.nextInt();
53      }
54  
55      /**
56       * @param max Upper bound (excluded).
57       * @return a random {@code int} value in the interval {@code [0, max)}.
58       */
59      protected int nextInt(int max) {
60          return rng.nextInt(max);
61      }
62  
63      /**
64       * @return a random {@code long} value.
65       */
66      protected long nextLong() {
67          return rng.nextLong();
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public String toString() {
73          return "rng=" + rng.toString();
74      }
75  }