public static Sampler linear(final double mean) {
		if (mean < 0 || mean >= 1 || !Double.isFinite(mean)) {
			throw new IllegalArgumentException(
				"Mean value not within allowed range [0, 1): %f."
					.formatted(mean)
			);
		}

		final class Range {
			static final double MIN = 0.0;
			static final double MAX = Math.nextDown(1.0);
			static final double LIMIT1 = 1.0 - 1.0/sqrt(2);
			static final double LIMIT2 = 1.0/sqrt(2);
			static double clamp(final double value) {
				return Math.clamp(value, MIN, MAX);
			}
		}

		if (Double.compare(mean, 0) == 0) {
			return (random, range) -> range.min();
		} else if (mean == Range.MAX) {
			return (random, range) -> Math.nextDown(range.max());
		}

		final double b, m;
		if (mean < Range.LIMIT1) {
			b = (2 - sqrt(2))/mean;
			m = -pow(b, 2)/2;
		} else if (mean < Range.LIMIT2) {
			b = (pow(mean, 2) - 0.5)/(pow(mean, 2) - mean);
			m = 2 - 2*b;
		} else if (mean < 1) {
			b = 0.5*(1 - pow(((2 - sqrt(2))/(1 - mean) - 1), 2));
			m = -b + sqrt(1 - 2*b) + 1;
		} else {
			b = m = 1;
		}

		return (random, range) -> {
			final var r = random.nextDouble();

			final double sample;
			if (mean < 0.5) {
				sample = Range.clamp((-b + sqrt(b*b + 2*r*m))/m);
			} else if (mean == 0.5) {
				sample = r;
			} else {
				sample = Range.clamp((b - sqrt(b*b + 2*m*(r - 1 + b + 0.5*m)))/-m);
			}

			return stretch(sample, range);
		};
	}
Return a new sampler for a <em>linear</em> distribution with the given
{@code mean} value, when creating sample points for the <em>normalized</em>
range {@code [0, 1)}.
<p>
	<img src="doc-files/LinearDistributionPDF.svg" width="450"
	     alt="Linear distribution sampler" >

@param mean the mean value of the sampler distribution
@return a new linear sampler with the given {@code mean} value
@throws IllegalArgumentException if the given {@code mean} value is not
        within the range {@code [0, 1)}
jenetics/src/main/java/io/jenetics/stat/Samplers.java