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       * Create an instance.
35       *
36       * @param rng Generator of uniformly distributed random numbers.
37       */
38      protected SamplerBase(UniformRandomProvider rng) {
39          this.rng = rng;
40      }
41  
42      /**
43       * Return the next {@code double} value.
44       *
45       * @return a random value from a uniform distribution in the
46       * interval {@code [0, 1)}.
47       */
48      protected double nextDouble() {
49          return rng.nextDouble();
50      }
51  
52      /**
53       * Return the next {@code int} value.
54       *
55       * @return a random {@code int} value.
56       */
57      protected int nextInt() {
58          return rng.nextInt();
59      }
60  
61      /**
62       * Return the next {@code int} value.
63       *
64       * @param max Upper bound (excluded).
65       * @return a random {@code int} value in the interval {@code [0, max)}.
66       */
67      protected int nextInt(int max) {
68          return rng.nextInt(max);
69      }
70  
71      /**
72       * Return the next {@code long} value.
73       *
74       * @return a random {@code long} value.
75       */
76      protected long nextLong() {
77          return rng.nextLong();
78      }
79  
80      /** {@inheritDoc} */
81      @Override
82      public String toString() {
83          return "rng=" + rng.toString();
84      }
85  }