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 {@link UniformRandomProvider#nextDouble()}.</p>
027 *
028 * @since 1.0
029 *
030 * @deprecated Since version 1.1. Please use {@link LogNormalSampler} instead.
031 */
032@Deprecated
033public class BoxMullerLogNormalSampler
034    extends SamplerBase
035    implements ContinuousSampler {
036    /** Delegate. */
037    private final ContinuousSampler sampler;
038
039    /**
040     * @param rng Generator of uniformly distributed random numbers.
041     * @param mu Mean of the natural logarithm of the distribution values.
042     * @param sigma Standard deviation of the natural logarithm of the distribution values.
043     * @throws IllegalArgumentException if {@code sigma <= 0}.
044     */
045    public BoxMullerLogNormalSampler(UniformRandomProvider rng,
046                                     double mu,
047                                     double sigma) {
048        super(null);
049        sampler = LogNormalSampler.of(new BoxMullerNormalizedGaussianSampler(rng),
050                                      mu, sigma);
051    }
052
053    /** {@inheritDoc} */
054    @Override
055    public double sample() {
056        return sampler.sample();
057    }
058
059    /** {@inheritDoc} */
060    @Override
061    public String toString() {
062        return sampler.toString();
063    }
064}