This is an automated email from the ASF dual-hosted git repository. erans pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-math.git
commit 759743122dc9dc1244566a2e4a774258efaedfdf Author: Gilles Sadowski <gillese...@gmail.com> AuthorDate: Thu Jun 10 03:10:21 2021 +0200 Removed "java.util.Random" wrapper. Utility is provided by "Commons RNG". --- .../commons/math4/legacy/random/RandomUtils.java | 104 --------------------- .../RandomUtilsDataGeneratorJDKRandomTest.java | 31 ------ 2 files changed, 135 deletions(-) diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/RandomUtils.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/RandomUtils.java index 60060e7..1387a4c 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/RandomUtils.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/RandomUtils.java @@ -49,110 +49,6 @@ public class RandomUtils { } /** - * Wraps an instance of the JDK's {@link Random} class. - * The actual generation of random numbers will be delegated to that - * instance. - * <p> - * If cryptographically secure data is required, one can use this - * factory method, with an instance of the {@link java.security.SecureRandom} - * class as the argument. - * Note that data generation will be much slower in this case. - * </p> - * - * @param rng Underlying generator. Reference is copied so the RNG - * is shared with the caller. - * @return a {@link DataGenerator data generator}. - */ - public static DataGenerator createDataGenerator(final Random rng) { - return createDataGenerator(asUniformRandomProvider(rng)); - } - - /** - * Wraps a {@link Random} instance. - * - * @param rng JDK {@link Random} instance to which the random number - * generation is delegated. Reference is copied so the RNG is shared - * with the caller. - * @return a {@link UniformRandomProvider} instance. - */ - public static UniformRandomProvider asUniformRandomProvider(final Random rng) { - return new UniformRandomProvider() { - /** {@inheritDoc} */ - @Override - public void nextBytes(byte[] bytes) { - rng.nextBytes(bytes); - } - - /** {@inheritDoc} */ - @Override - public void nextBytes(byte[] bytes, - int start, - int len) { - final byte[] reduced = new byte[len]; - rng.nextBytes(reduced); - System.arraycopy(reduced, 0, bytes, start, len); - } - - /** {@inheritDoc} */ - @Override - public int nextInt() { - return rng.nextInt(); - } - - /** {@inheritDoc} */ - @Override - public int nextInt(int n) { - if (n <= 0) { - throw new NotStrictlyPositiveException(n); - } - return rng.nextInt(n); - } - - /** {@inheritDoc} */ - @Override - public long nextLong() { - return rng.nextLong(); - } - - /** {@inheritDoc} */ - @Override - public long nextLong(long n) { - // Code copied from "o.a.c.m.rng.internal.BaseProvider". - - if (n > 0) { - long bits; - long val; - do { - bits = rng.nextLong() >>> 1; - val = bits % n; - } while (bits - val + (n - 1) < 0); - return val; - } - - throw new NotStrictlyPositiveException(n); - } - - /** {@inheritDoc} */ - @Override - public boolean nextBoolean() { - return rng.nextBoolean(); - } - - /** {@inheritDoc} */ - @Override - public float nextFloat() { - return rng.nextFloat(); - } - - /** {@inheritDoc} */ - @Override - public double nextDouble() { - return rng.nextDouble(); - } - }; - } - - /** * Various random data generation routines. */ public static class DataGenerator { diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/random/RandomUtilsDataGeneratorJDKRandomTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/random/RandomUtilsDataGeneratorJDKRandomTest.java deleted file mode 100644 index f19a8b9..0000000 --- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/random/RandomUtilsDataGeneratorJDKRandomTest.java +++ /dev/null @@ -1,31 +0,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. - */ -package org.apache.commons.math4.legacy.random; - -import java.util.Random; - -/** - * Test cases for the {@link RandomUtils.DataGenerator} class, using - * {@link Random} as the underlying source of randomness. - */ -public class RandomUtilsDataGeneratorJDKRandomTest - extends RandomUtilsDataGeneratorAbstractTest { - - public RandomUtilsDataGeneratorJDKRandomTest() { - super(RandomUtils.asUniformRandomProvider(new Random(1000))); - } -}