| <?xml version="1.0"?> |
| |
| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| |
| <document> |
| |
| <properties> |
| <title>Commons RNG Sampling</title> |
| </properties> |
| |
| <body> |
| |
| <section name="Apache Commons RNG: Random Numbers Generators" href="summary"> |
| <p> |
| Commons RNG provides implementations of pseudo-random numbers generators that are |
| faster; of higher quality; and/or of a longer period than |
| <code>java.util.Random</code> and <code>java.util.SplittableRandom</code>. |
| </p> |
| |
| <p> |
| The "sampling" module contains classes to generate samples that follow the statistics |
| of a given distribution. |
| </p> |
| |
| <p> |
| Example: |
| |
| <source class="prettyprint">import org.apache.commons.rng.UniformRandomProvider; |
| import org.apache.commons.rng.sampling.distribution.ContinuousSampler; |
| import org.apache.commons.rng.sampling.distribution.ZigguratSampler.Gaussian; |
| |
| public class NormalDeviates { |
| private final ContinuousSampler normalizedGaussian; |
| |
| public NormalDeviates(UniformRandomProvider rng) { |
| normalizedGaussian = ZigguratSampler.Gaussian.of(rng); |
| } |
| |
| public double sample(double mean, |
| double sigma) { |
| return mean + sigma * normalizedGaussian.sample(); |
| } |
| } |
| </source> |
| </p> |
| |
| <p> |
| Utilities are provided to sample from generic collections. |
| </p> |
| |
| <p> |
| Example: |
| |
| <source class="prettyprint">import org.apache.commons.rng.UniformRandomProvider; |
| import java.util.HashSet; |
| import org.apache.commons.rng.sampling.CollectionSampler; |
| |
| HashSet<String> elements = new HashSet<>(); |
| elements.add("Apache"); |
| elements.add("Commons"); |
| elements.add("RNG"); |
| |
| CollectionSampler<String> sampler = new CollectionSampler<>(RandomSource.MWC_256.create(), |
| elements); |
| String word = sampler.sample(); |
| </source> |
| </p> |
| |
| <p> |
| The module also contains classes to generate coordinate samples from geometric shapes |
| such as inside a ball, box or triangle or on the surface of a sphere. |
| </p> |
| |
| <p> |
| Example: |
| |
| <source class="prettyprint">import org.apache.commons.rng.UniformRandomProvider; |
| import org.apache.commons.rng.sampling.UnitSphereSampler; |
| |
| int dimension = 3; |
| UnitSphereSampler sampler = UnitSphereSampler.of(dimension, RandomSource.KISS.create()); |
| |
| double[] vector = sampler.sample(); |
| </source> |
| </p> |
| |
| <p> |
| Browse the <a href="apidocs/index.html">Javadoc</a> for more information. |
| </p> |
| </section> |
| |
| </body> |
| |
| </document> |