001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  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 */
017package org.apache.commons.rng.sampling.distribution;
018
019import org.apache.commons.rng.UniformRandomProvider;
020
021/**
022 * Sampling from a <a href="https://en.wikipedia.org/wiki/Log-normal_distribution">
023 * log-normal distribution</a>.
024 * Uses {@link BoxMullerNormalizedGaussianSampler} as the underlying sampler.
025 *
026 * <p>Sampling uses:</p>
027 *
028 * <ul>
029 *   <li>{@link UniformRandomProvider#nextDouble()}
030 *   <li>{@link UniformRandomProvider#nextLong()}
031 * </ul>
032 *
033 * @since 1.0
034 *
035 * @deprecated Since version 1.1. Please use {@link LogNormalSampler} instead.
036 */
037@Deprecated
038public class BoxMullerLogNormalSampler
039    extends SamplerBase
040    implements ContinuousSampler {
041    /** Delegate. */
042    private final ContinuousSampler sampler;
043
044    /**
045     * Create an instance.
046     *
047     * @param rng Generator of uniformly distributed random numbers.
048     * @param mu Mean of the natural logarithm of the distribution values.
049     * @param sigma Standard deviation of the natural logarithm of the distribution values.
050     * @throws IllegalArgumentException if {@code sigma <= 0}.
051     */
052    public BoxMullerLogNormalSampler(UniformRandomProvider rng,
053                                     double mu,
054                                     double sigma) {
055        super(null);
056        sampler = LogNormalSampler.of(new BoxMullerNormalizedGaussianSampler(rng),
057                                      mu, sigma);
058    }
059
060    /** {@inheritDoc} */
061    @Override
062    public double sample() {
063        return sampler.sample();
064    }
065
066    /** {@inheritDoc} */
067    @Override
068    public String toString() {
069        return sampler.toString();
070    }
071}