Re: [PR] RNG-188: Add Philox4x32 and Philox4x64 random number generators [commons-rng]
aherbert merged PR #191: URL: https://github.com/apache/commons-rng/pull/191 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] RNG-188: Add Philox4x32 and Philox4x64 random number generators [commons-rng]
aherbert commented on PR #191: URL: https://github.com/apache/commons-rng/pull/191#issuecomment-3890676263 Sorry, the master branch run an invalid integration test. I've corrected the dependencies for that. If you rebase on master then hopefully this will pass CI on all tested JDKs. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] RNG-188: Add Philox4x32 and Philox4x64 random number generators [commons-rng]
aherbert commented on PR #191: URL: https://github.com/apache/commons-rng/pull/191#issuecomment-3885884471 I am fine to merge this when it passes the CI build. Currently it is failing on a malformed javadoc tag. I do not know why so it may just need reformatting to a single line. If you can run the default maven goal locally (using `mvn`) then you should see the error. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] RNG-188: Add Philox4x32 and Philox4x64 random number generators [commons-rng]
aherbert commented on code in PR #191:
URL: https://github.com/apache/commons-rng/pull/191#discussion_r2789265387
##
commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/Philox4x64Test.java:
##
@@ -0,0 +1,203 @@
+/*
+ * 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.rng.core.source64;
+
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.core.RandomAssert;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class Philox4x64Test {
+/*
+ * Data from python randomgen.philox.Philox(key=1234,number=4,width=32)
random_raw()
+ * https://bashtage.github.io/randomgen/bit_generators/philox.html
+ */
+
+private static final long[] EXPECTED_SEQUENCE_1234 = {
+6174562084317992592L, -7568142518571726206L, -5685918792241859306L,
+6151287208724416091L, -7525285015497232737L, -2526119061336846091L,
+-2093373494943999176L, 2505686065164099867L, 1493954073060533072L,
+2386252059344830309L, -3981277096068706128L, 4825385527958964709L,
+5896359280427319232L, 2130638389021018825L, 1001529696243618836L,
+6229771985419955916L, -8030183820248387325L, 5924921954534026109L,
+-2430661683740471500L, -7119094164204651921L, 2451935767711287279L,
+8424479353221384040L, -5011970289299902244L, 8792348508803652203L,
+9109768561113011588L, 24126314432238277L, -8946976403367747978L,
+6224712922535513938L, 8733921062828259483L, 3855129282970288492L,
+-15371244630355388L, -3103082637265535013L, -5696416329331263984L,
+-5000982493478729316L, -3077201427991874994L, 4502749081228919907L,
+1930363720599024367L, -7884649763770700010L, 9162677665382083018L,
+-1491083349895074892L
+};
+
+private static final long[] EXPECTED_SEQUENCE_DEFAULT = {
+7651105821017786633L, -986727441099762072L, -1758232618730818806L,
+-6892647654339096064L, 2003912625120555464L, 847995992558080923L,
+2561190448322591348L, 5089323078274549892L, -6215224099279536444L,
+2839273132443259286L, -1538091565590055595L, 2262400997606952131L,
+4794890345824897152L, 2654554423835782039L, 5232844452212050618L,
+4968309811735346778L, -6677562093502275256L, -2345486924693103657L,
+2546479265789531422L, 1397198500311783458L, -3029924206687987745L,
+3915450377326980183L, -1798629713529533718L, 7813856890368443409L,
+-7530219763187390588L, 7752320264114599504L, 4497386005519180400L,
+8983526426341050924L, 3157770966203722859L, 6531619948763639990L,
+-2561361262383382379L, -7341089376366770572L, 5588349311041971766L,
+-5547961913507498237L, 557535079196835645L, -7564858493373145745L,
+-5687482083658299050L, -6040393957990987713L, 3376696212464637986L,
+-4460669316800568753L
+};
+
+private static final long[] EXPECTED_SEQUENCE_AFTER_JUMP = {
+-8246258822028745854L, -8108712508154901372L, 2654408923912105318L,
+-6418747939867464899L, 8695124057120477387L, -4062778777418832523L,
+-2866609061902870832L, -1985485291750970064L, -3716513824860297891L,
+2708966168515282018L, -8441862438570589384L, -3332504021977608920L,
+8275431876927502767L, -37683753608778224L, 4850475723424833501L,
+-2864632267522668999L, -6547048909303846355L, -6804759155034193445L,
+-1607076952104749058L, 7993605125443204784L, 7601442483044023354L,
+-7379694727972198096L, -190253666483395L, -908773878773086264L,
+-7367142976738044337L, 2845297286559921499L, 5398165976383543580L,
+2574122219286874876L, 3780790808954139828L, -7038343169285503987L,
+1381442423564430946L, -4910467881295472851L, 839863310680617535L,
+3700507604505113976L, 2586645934793105407L, 1058068213122536369L,
+-1876209807038423750L, 8994121856634859944L, 4145729862086221315L,
+-7214331765643557828L
+};
+
+private static final long[] EXPECTED_SEQUENCE_AFTER_LONG_JUMP = {
+234199833207670492L, 4847236961490835302L, 4652995647109309910L,
+-3737386356448340712L, -5273383
Re: [PR] RNG-188: Add Philox4x32 and Philox4x64 random number generators [commons-rng]
jherekhealy commented on PR #191: URL: https://github.com/apache/commons-rng/pull/191#issuecomment-3879267495 Thanks for your detailed comments. I have attempted to address most of them in the latest commit. Regarding your question on TestU01, yes, it passes BigCrush - this is detailed in the original paper https://dl.acm.org/doi/epdf/10.1145/2063384.2063405 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] RNG-188: Add Philox4x32 and Philox4x64 random number generators [commons-rng]
jherekhealy commented on code in PR #191:
URL: https://github.com/apache/commons-rng/pull/191#discussion_r2788566433
##
commons-rng-core/src/main/java/org/apache/commons/rng/core/source32/Philox4x32.java:
##
@@ -0,0 +1,431 @@
+/*
+ * 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.rng.core.source32;
+
+import org.apache.commons.rng.JumpableUniformRandomProvider;
+import org.apache.commons.rng.LongJumpableUniformRandomProvider;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.core.util.NumberFactory;
+
+/**
+ * This class implements the Philox4x32 128-bit counter-based generator with
10 rounds.
+ * Jumping in the sequence is essentially instantaneous. This generator
provides subsequences for easy parallelization.
+ *
+ * @see https://www.thesalmons.org/john/random123/papers/random123sc11.pdf";>Parallel
Random Numbers: As Easy as 1,2,3
+ * for details regarding the engine.
+ * @since 1.7
+ */
+public final class Philox4x32 extends IntProvider implements
LongJumpableUniformRandomProvider {
+/**
+ * Philox 32-bit mixing constant for counter 0.
+ */
+private static final int K_PHILOX_10_A = 0x9E3779B9;
+/**
+ * Philox 32-bit mixing constant for counter 1.
+ */
+private static final int K_PHILOX_10_B = 0xBB67AE85;
+/**
+ * Philox 32-bit constant for key 0.
+ */
+private static final int K_PHILOX_SA = 0xD2511F53;
+/**
+ * Philox 32-bit constant for key 1.
+ */
+private static final int K_PHILOX_SB = 0xCD9E8D57;
+/**
+ * Internal buffer size.
+ */
+private static final int PHILOX_BUFFER_SIZE = 4;
+/**
+ * number of int variables.
+ */
+private static final int STATE_SIZE = 7;
+
+/**
+ * Counter 0.
+ */
+private int counter0;
+/**
+ * Counter 1.
+ */
+private int counter1;
+/**
+ * Counter 2.
+ */
+private int counter2;
+/**
+ * Counter 3.
+ */
+private int counter3;
+/**
+ * Output point.
+ */
+private int[] buffer = new int[PHILOX_BUFFER_SIZE]; // UINT4
+/**
+ * Key low bits.
+ */
+private int key0;
+/**
+ * Key high bits.
+ */
+private int key1;
+/**
+ * State index: which output word is next (0..3).
+ */
+private int bufferPosition;
+
+
+/**
+ * Copy constructor.
+ *
+ * @param source Source to copy.
+ */
+private Philox4x32(Philox4x32 source) {
+super(source);
+counter0 = source.counter0;
+counter1 = source.counter1;
+counter2 = source.counter2;
+counter3 = source.counter3;
+key0 = source.key0;
+key1 = source.key1;
+bufferPosition = source.bufferPosition;
+buffer = source.buffer.clone();
+}
+
+/**
+ * Creates a new instance with default seed. Subsequence and offset are
set to zero.
+ */
+public Philox4x32() {
+this(67280421310721L, 0L, 0L);
+}
+
+/**
+ * Creates a new instance with given seed. Subsequence and offset are set
to zero.
+ *
+ * @param seed Initial seed.
+ */
+public Philox4x32(long seed) {
+this(seed, 0L, 0L);
+}
+
+/**
+ * Creates a new instance. Offset and subsequence determine the internal
counter of Philox.
+ *
+ * @param seedInitial seed.
+ * @param subsequence a subsequence index
+ * @param offset an offset, zero for the first number.
+ */
+public Philox4x32(long seed, long subsequence, long offset) {
+resetState(seed, subsequence);
+incrementCounter(offset);
+}
+
+/**
+ * Creates a new instance based on an array of int containing, seed,
subsequence and offset.
+ *
+ * @param seed key0,key1,counter0,counter1,counter2,counter3.
+ */
+@SuppressWarnings("PMD.AvoidLiteralsInIfCondition")
+public Philox4x32(int... seed) {
+key0 = seed[0];
+if (seed.length > 1) {
+key1 = seed[1];
+} else {
+key1 = 0;
+}
+if (seed.length > 2) {
+counter0 = seed[2];
+} else {
+counter0 = 0;
+}
+
Re: [PR] RNG-188: Add Philox4x32 and Philox4x64 random number generators [commons-rng]
jherekhealy commented on code in PR #191: URL: https://github.com/apache/commons-rng/pull/191#discussion_r2788554701 ## commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/ProviderBuilder.java: ## @@ -16,45 +16,51 @@ */ package org.apache.commons.rng.simple.internal; -import java.lang.reflect.Array; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; - -import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.RestorableUniformRandomProvider; +import org.apache.commons.rng.UniformRandomProvider; Review Comment: ok -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] RNG-188: Add Philox4x32 and Philox4x64 random number generators [commons-rng]
jherekhealy commented on code in PR #191:
URL: https://github.com/apache/commons-rng/pull/191#discussion_r2788536681
##
commons-rng-core/src/main/java/org/apache/commons/rng/core/source32/Philox4x32.java:
##
@@ -0,0 +1,431 @@
+/*
+ * 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.rng.core.source32;
+
+import org.apache.commons.rng.JumpableUniformRandomProvider;
+import org.apache.commons.rng.LongJumpableUniformRandomProvider;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.core.util.NumberFactory;
+
+/**
+ * This class implements the Philox4x32 128-bit counter-based generator with
10 rounds.
+ * Jumping in the sequence is essentially instantaneous. This generator
provides subsequences for easy parallelization.
+ *
+ * @see https://www.thesalmons.org/john/random123/papers/random123sc11.pdf";>Parallel
Random Numbers: As Easy as 1,2,3
+ * for details regarding the engine.
+ * @since 1.7
+ */
+public final class Philox4x32 extends IntProvider implements
LongJumpableUniformRandomProvider {
+/**
+ * Philox 32-bit mixing constant for counter 0.
+ */
+private static final int K_PHILOX_10_A = 0x9E3779B9;
+/**
+ * Philox 32-bit mixing constant for counter 1.
+ */
+private static final int K_PHILOX_10_B = 0xBB67AE85;
+/**
+ * Philox 32-bit constant for key 0.
+ */
+private static final int K_PHILOX_SA = 0xD2511F53;
+/**
+ * Philox 32-bit constant for key 1.
+ */
+private static final int K_PHILOX_SB = 0xCD9E8D57;
+/**
+ * Internal buffer size.
+ */
+private static final int PHILOX_BUFFER_SIZE = 4;
+/**
+ * number of int variables.
+ */
+private static final int STATE_SIZE = 7;
+
+/**
+ * Counter 0.
+ */
+private int counter0;
+/**
+ * Counter 1.
+ */
+private int counter1;
+/**
+ * Counter 2.
+ */
+private int counter2;
+/**
+ * Counter 3.
+ */
+private int counter3;
+/**
+ * Output point.
+ */
+private int[] buffer = new int[PHILOX_BUFFER_SIZE]; // UINT4
+/**
+ * Key low bits.
+ */
+private int key0;
+/**
+ * Key high bits.
+ */
+private int key1;
+/**
+ * State index: which output word is next (0..3).
+ */
+private int bufferPosition;
+
+
+/**
+ * Copy constructor.
+ *
+ * @param source Source to copy.
+ */
+private Philox4x32(Philox4x32 source) {
+super(source);
+counter0 = source.counter0;
+counter1 = source.counter1;
+counter2 = source.counter2;
+counter3 = source.counter3;
+key0 = source.key0;
+key1 = source.key1;
+bufferPosition = source.bufferPosition;
+buffer = source.buffer.clone();
+}
+
+/**
+ * Creates a new instance with default seed. Subsequence and offset are
set to zero.
+ */
+public Philox4x32() {
+this(67280421310721L, 0L, 0L);
+}
+
+/**
+ * Creates a new instance with given seed. Subsequence and offset are set
to zero.
+ *
+ * @param seed Initial seed.
+ */
+public Philox4x32(long seed) {
+this(seed, 0L, 0L);
+}
+
+/**
+ * Creates a new instance. Offset and subsequence determine the internal
counter of Philox.
+ *
+ * @param seedInitial seed.
+ * @param subsequence a subsequence index
+ * @param offset an offset, zero for the first number.
+ */
+public Philox4x32(long seed, long subsequence, long offset) {
+resetState(seed, subsequence);
+incrementCounter(offset);
+}
+
+/**
+ * Creates a new instance based on an array of int containing, seed,
subsequence and offset.
+ *
+ * @param seed key0,key1,counter0,counter1,counter2,counter3.
+ */
+@SuppressWarnings("PMD.AvoidLiteralsInIfCondition")
+public Philox4x32(int... seed) {
+key0 = seed[0];
+if (seed.length > 1) {
+key1 = seed[1];
+} else {
+key1 = 0;
+}
+if (seed.length > 2) {
+counter0 = seed[2];
+} else {
+counter0 = 0;
+}
+
Re: [PR] RNG-188: Add Philox4x32 and Philox4x64 random number generators [commons-rng]
jherekhealy commented on code in PR #191:
URL: https://github.com/apache/commons-rng/pull/191#discussion_r278846
##
commons-rng-core/src/main/java/org/apache/commons/rng/core/source32/Philox4x32.java:
##
@@ -0,0 +1,431 @@
+/*
+ * 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.rng.core.source32;
+
+import org.apache.commons.rng.JumpableUniformRandomProvider;
+import org.apache.commons.rng.LongJumpableUniformRandomProvider;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.core.util.NumberFactory;
+
+/**
+ * This class implements the Philox4x32 128-bit counter-based generator with
10 rounds.
+ * Jumping in the sequence is essentially instantaneous. This generator
provides subsequences for easy parallelization.
+ *
+ * @see https://www.thesalmons.org/john/random123/papers/random123sc11.pdf";>Parallel
Random Numbers: As Easy as 1,2,3
+ * for details regarding the engine.
+ * @since 1.7
+ */
+public final class Philox4x32 extends IntProvider implements
LongJumpableUniformRandomProvider {
+/**
+ * Philox 32-bit mixing constant for counter 0.
+ */
+private static final int K_PHILOX_10_A = 0x9E3779B9;
+/**
+ * Philox 32-bit mixing constant for counter 1.
+ */
+private static final int K_PHILOX_10_B = 0xBB67AE85;
+/**
+ * Philox 32-bit constant for key 0.
+ */
+private static final int K_PHILOX_SA = 0xD2511F53;
+/**
+ * Philox 32-bit constant for key 1.
+ */
+private static final int K_PHILOX_SB = 0xCD9E8D57;
+/**
+ * Internal buffer size.
+ */
+private static final int PHILOX_BUFFER_SIZE = 4;
+/**
+ * number of int variables.
+ */
+private static final int STATE_SIZE = 7;
+
+/**
+ * Counter 0.
+ */
+private int counter0;
+/**
+ * Counter 1.
+ */
+private int counter1;
+/**
+ * Counter 2.
+ */
+private int counter2;
+/**
+ * Counter 3.
+ */
+private int counter3;
+/**
+ * Output point.
+ */
+private int[] buffer = new int[PHILOX_BUFFER_SIZE]; // UINT4
+/**
+ * Key low bits.
+ */
+private int key0;
+/**
+ * Key high bits.
+ */
+private int key1;
+/**
+ * State index: which output word is next (0..3).
+ */
+private int bufferPosition;
+
+
+/**
+ * Copy constructor.
+ *
+ * @param source Source to copy.
+ */
+private Philox4x32(Philox4x32 source) {
+super(source);
+counter0 = source.counter0;
+counter1 = source.counter1;
+counter2 = source.counter2;
+counter3 = source.counter3;
+key0 = source.key0;
+key1 = source.key1;
+bufferPosition = source.bufferPosition;
+buffer = source.buffer.clone();
+}
+
+/**
+ * Creates a new instance with default seed. Subsequence and offset are
set to zero.
+ */
+public Philox4x32() {
+this(67280421310721L, 0L, 0L);
+}
+
+/**
+ * Creates a new instance with given seed. Subsequence and offset are set
to zero.
+ *
+ * @param seed Initial seed.
+ */
+public Philox4x32(long seed) {
+this(seed, 0L, 0L);
+}
+
+/**
+ * Creates a new instance. Offset and subsequence determine the internal
counter of Philox.
+ *
+ * @param seedInitial seed.
+ * @param subsequence a subsequence index
+ * @param offset an offset, zero for the first number.
+ */
+public Philox4x32(long seed, long subsequence, long offset) {
+resetState(seed, subsequence);
+incrementCounter(offset);
+}
+
+/**
+ * Creates a new instance based on an array of int containing, seed,
subsequence and offset.
+ *
+ * @param seed key0,key1,counter0,counter1,counter2,counter3.
+ */
+@SuppressWarnings("PMD.AvoidLiteralsInIfCondition")
+public Philox4x32(int... seed) {
Review Comment:
much nicer indeed!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
Re: [PR] RNG-188: Add Philox4x32 and Philox4x64 random number generators [commons-rng]
jherekhealy commented on code in PR #191:
URL: https://github.com/apache/commons-rng/pull/191#discussion_r2788442502
##
commons-rng-core/src/main/java/org/apache/commons/rng/core/source32/Philox4x32.java:
##
@@ -0,0 +1,431 @@
+/*
+ * 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.rng.core.source32;
+
+import org.apache.commons.rng.JumpableUniformRandomProvider;
+import org.apache.commons.rng.LongJumpableUniformRandomProvider;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.core.util.NumberFactory;
+
+/**
+ * This class implements the Philox4x32 128-bit counter-based generator with
10 rounds.
+ * Jumping in the sequence is essentially instantaneous. This generator
provides subsequences for easy parallelization.
+ *
+ * @see https://www.thesalmons.org/john/random123/papers/random123sc11.pdf";>Parallel
Random Numbers: As Easy as 1,2,3
+ * for details regarding the engine.
+ * @since 1.7
+ */
+public final class Philox4x32 extends IntProvider implements
LongJumpableUniformRandomProvider {
+/**
+ * Philox 32-bit mixing constant for counter 0.
+ */
+private static final int K_PHILOX_10_A = 0x9E3779B9;
+/**
+ * Philox 32-bit mixing constant for counter 1.
+ */
+private static final int K_PHILOX_10_B = 0xBB67AE85;
+/**
+ * Philox 32-bit constant for key 0.
+ */
+private static final int K_PHILOX_SA = 0xD2511F53;
+/**
+ * Philox 32-bit constant for key 1.
+ */
+private static final int K_PHILOX_SB = 0xCD9E8D57;
+/**
+ * Internal buffer size.
+ */
+private static final int PHILOX_BUFFER_SIZE = 4;
+/**
+ * number of int variables.
+ */
+private static final int STATE_SIZE = 7;
+
+/**
+ * Counter 0.
+ */
+private int counter0;
+/**
+ * Counter 1.
+ */
+private int counter1;
+/**
+ * Counter 2.
+ */
+private int counter2;
+/**
+ * Counter 3.
+ */
+private int counter3;
+/**
+ * Output point.
+ */
+private int[] buffer = new int[PHILOX_BUFFER_SIZE]; // UINT4
+/**
+ * Key low bits.
+ */
+private int key0;
+/**
+ * Key high bits.
+ */
+private int key1;
+/**
+ * State index: which output word is next (0..3).
+ */
+private int bufferPosition;
+
+
+/**
+ * Copy constructor.
+ *
+ * @param source Source to copy.
+ */
+private Philox4x32(Philox4x32 source) {
+super(source);
+counter0 = source.counter0;
+counter1 = source.counter1;
+counter2 = source.counter2;
+counter3 = source.counter3;
+key0 = source.key0;
+key1 = source.key1;
+bufferPosition = source.bufferPosition;
+buffer = source.buffer.clone();
+}
+
+/**
+ * Creates a new instance with default seed. Subsequence and offset are
set to zero.
+ */
+public Philox4x32() {
+this(67280421310721L, 0L, 0L);
+}
+
+/**
+ * Creates a new instance with given seed. Subsequence and offset are set
to zero.
+ *
+ * @param seed Initial seed.
+ */
+public Philox4x32(long seed) {
+this(seed, 0L, 0L);
+}
+
+/**
+ * Creates a new instance. Offset and subsequence determine the internal
counter of Philox.
+ *
+ * @param seedInitial seed.
+ * @param subsequence a subsequence index
+ * @param offset an offset, zero for the first number.
+ */
+public Philox4x32(long seed, long subsequence, long offset) {
+resetState(seed, subsequence);
+incrementCounter(offset);
+}
+
+/**
+ * Creates a new instance based on an array of int containing, seed,
subsequence and offset.
+ *
+ * @param seed key0,key1,counter0,counter1,counter2,counter3.
+ */
+@SuppressWarnings("PMD.AvoidLiteralsInIfCondition")
+public Philox4x32(int... seed) {
+key0 = seed[0];
+if (seed.length > 1) {
+key1 = seed[1];
+} else {
+key1 = 0;
+}
+if (seed.length > 2) {
+counter0 = seed[2];
+} else {
+counter0 = 0;
+}
+
Re: [PR] RNG-188: Add Philox4x32 and Philox4x64 random number generators [commons-rng]
jherekhealy commented on code in PR #191:
URL: https://github.com/apache/commons-rng/pull/191#discussion_r2788437175
##
commons-rng-core/src/main/java/org/apache/commons/rng/core/source32/Philox4x32.java:
##
@@ -0,0 +1,431 @@
+/*
+ * 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.rng.core.source32;
+
+import org.apache.commons.rng.JumpableUniformRandomProvider;
+import org.apache.commons.rng.LongJumpableUniformRandomProvider;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.core.util.NumberFactory;
+
+/**
+ * This class implements the Philox4x32 128-bit counter-based generator with
10 rounds.
+ * Jumping in the sequence is essentially instantaneous. This generator
provides subsequences for easy parallelization.
+ *
+ * @see https://www.thesalmons.org/john/random123/papers/random123sc11.pdf";>Parallel
Random Numbers: As Easy as 1,2,3
+ * for details regarding the engine.
+ * @since 1.7
+ */
+public final class Philox4x32 extends IntProvider implements
LongJumpableUniformRandomProvider {
+/**
+ * Philox 32-bit mixing constant for counter 0.
+ */
+private static final int K_PHILOX_10_A = 0x9E3779B9;
+/**
+ * Philox 32-bit mixing constant for counter 1.
+ */
+private static final int K_PHILOX_10_B = 0xBB67AE85;
+/**
+ * Philox 32-bit constant for key 0.
+ */
+private static final int K_PHILOX_SA = 0xD2511F53;
+/**
+ * Philox 32-bit constant for key 1.
+ */
+private static final int K_PHILOX_SB = 0xCD9E8D57;
+/**
+ * Internal buffer size.
+ */
+private static final int PHILOX_BUFFER_SIZE = 4;
+/**
+ * number of int variables.
+ */
+private static final int STATE_SIZE = 7;
+
+/**
+ * Counter 0.
+ */
+private int counter0;
+/**
+ * Counter 1.
+ */
+private int counter1;
+/**
+ * Counter 2.
+ */
+private int counter2;
+/**
+ * Counter 3.
+ */
+private int counter3;
+/**
+ * Output point.
+ */
+private int[] buffer = new int[PHILOX_BUFFER_SIZE]; // UINT4
+/**
+ * Key low bits.
+ */
+private int key0;
+/**
+ * Key high bits.
+ */
+private int key1;
+/**
+ * State index: which output word is next (0..3).
+ */
+private int bufferPosition;
+
+
+/**
+ * Copy constructor.
+ *
+ * @param source Source to copy.
+ */
+private Philox4x32(Philox4x32 source) {
+super(source);
+counter0 = source.counter0;
+counter1 = source.counter1;
+counter2 = source.counter2;
+counter3 = source.counter3;
+key0 = source.key0;
+key1 = source.key1;
+bufferPosition = source.bufferPosition;
+buffer = source.buffer.clone();
+}
+
+/**
+ * Creates a new instance with default seed. Subsequence and offset are
set to zero.
+ */
+public Philox4x32() {
+this(67280421310721L, 0L, 0L);
+}
+
+/**
+ * Creates a new instance with given seed. Subsequence and offset are set
to zero.
+ *
+ * @param seed Initial seed.
+ */
+public Philox4x32(long seed) {
+this(seed, 0L, 0L);
+}
+
+/**
+ * Creates a new instance. Offset and subsequence determine the internal
counter of Philox.
+ *
+ * @param seedInitial seed.
+ * @param subsequence a subsequence index
+ * @param offset an offset, zero for the first number.
+ */
+public Philox4x32(long seed, long subsequence, long offset) {
+resetState(seed, subsequence);
+incrementCounter(offset);
+}
+
+/**
+ * Creates a new instance based on an array of int containing, seed,
subsequence and offset.
+ *
+ * @param seed key0,key1,counter0,counter1,counter2,counter3.
+ */
+@SuppressWarnings("PMD.AvoidLiteralsInIfCondition")
+public Philox4x32(int... seed) {
+key0 = seed[0];
+if (seed.length > 1) {
+key1 = seed[1];
+} else {
+key1 = 0;
+}
+if (seed.length > 2) {
+counter0 = seed[2];
+} else {
+counter0 = 0;
+}
+
Re: [PR] RNG-188: Add Philox4x32 and Philox4x64 random number generators [commons-rng]
jherekhealy commented on code in PR #191:
URL: https://github.com/apache/commons-rng/pull/191#discussion_r2788424358
##
commons-rng-core/src/main/java/org/apache/commons/rng/core/source32/Philox4x32.java:
##
@@ -0,0 +1,431 @@
+/*
+ * 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.rng.core.source32;
+
+import org.apache.commons.rng.JumpableUniformRandomProvider;
+import org.apache.commons.rng.LongJumpableUniformRandomProvider;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.core.util.NumberFactory;
+
+/**
+ * This class implements the Philox4x32 128-bit counter-based generator with
10 rounds.
+ * Jumping in the sequence is essentially instantaneous. This generator
provides subsequences for easy parallelization.
+ *
+ * @see https://www.thesalmons.org/john/random123/papers/random123sc11.pdf";>Parallel
Random Numbers: As Easy as 1,2,3
+ * for details regarding the engine.
+ * @since 1.7
+ */
+public final class Philox4x32 extends IntProvider implements
LongJumpableUniformRandomProvider {
+/**
+ * Philox 32-bit mixing constant for counter 0.
+ */
+private static final int K_PHILOX_10_A = 0x9E3779B9;
+/**
+ * Philox 32-bit mixing constant for counter 1.
+ */
+private static final int K_PHILOX_10_B = 0xBB67AE85;
+/**
+ * Philox 32-bit constant for key 0.
+ */
+private static final int K_PHILOX_SA = 0xD2511F53;
+/**
+ * Philox 32-bit constant for key 1.
+ */
+private static final int K_PHILOX_SB = 0xCD9E8D57;
+/**
+ * Internal buffer size.
+ */
+private static final int PHILOX_BUFFER_SIZE = 4;
+/**
+ * number of int variables.
+ */
+private static final int STATE_SIZE = 7;
+
+/**
+ * Counter 0.
+ */
+private int counter0;
+/**
+ * Counter 1.
+ */
+private int counter1;
+/**
+ * Counter 2.
+ */
+private int counter2;
+/**
+ * Counter 3.
+ */
+private int counter3;
+/**
+ * Output point.
+ */
+private int[] buffer = new int[PHILOX_BUFFER_SIZE]; // UINT4
+/**
+ * Key low bits.
+ */
+private int key0;
+/**
+ * Key high bits.
+ */
+private int key1;
+/**
+ * State index: which output word is next (0..3).
+ */
+private int bufferPosition;
+
+
+/**
+ * Copy constructor.
+ *
+ * @param source Source to copy.
+ */
+private Philox4x32(Philox4x32 source) {
+super(source);
+counter0 = source.counter0;
+counter1 = source.counter1;
+counter2 = source.counter2;
+counter3 = source.counter3;
+key0 = source.key0;
+key1 = source.key1;
+bufferPosition = source.bufferPosition;
+buffer = source.buffer.clone();
+}
+
+/**
+ * Creates a new instance with default seed. Subsequence and offset are
set to zero.
+ */
+public Philox4x32() {
+this(67280421310721L, 0L, 0L);
+}
+
+/**
+ * Creates a new instance with given seed. Subsequence and offset are set
to zero.
+ *
+ * @param seed Initial seed.
+ */
+public Philox4x32(long seed) {
+this(seed, 0L, 0L);
+}
+
+/**
+ * Creates a new instance. Offset and subsequence determine the internal
counter of Philox.
+ *
+ * @param seedInitial seed.
+ * @param subsequence a subsequence index
+ * @param offset an offset, zero for the first number.
+ */
+public Philox4x32(long seed, long subsequence, long offset) {
+resetState(seed, subsequence);
+incrementCounter(offset);
+}
+
+/**
+ * Creates a new instance based on an array of int containing, seed,
subsequence and offset.
+ *
+ * @param seed key0,key1,counter0,counter1,counter2,counter3.
+ */
+@SuppressWarnings("PMD.AvoidLiteralsInIfCondition")
+public Philox4x32(int... seed) {
+key0 = seed[0];
+if (seed.length > 1) {
+key1 = seed[1];
+} else {
+key1 = 0;
+}
+if (seed.length > 2) {
+counter0 = seed[2];
+} else {
+counter0 = 0;
+}
+
