<commit_before>/*
 * Java Genetic Algorithm Library (@__identifier__@).
 * Copyright (c) @__year__@ <NAME>
 *
 * Licensed 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.
 *
 * Author:
 *    <NAME> (<EMAIL>)
 */
package org.jenetix.random;

import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
import static org.jenetics.internal.util.Equality.eq;

import java.io.Serializable;
import java.util.Optional;
import java.util.Random;

import org.jenetics.internal.util.Equality;
import org.jenetics.internal.util.Hash;

import org.jenetics.util.Random32;
import org.jenetics.util.math;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @since !__version__!
 * @version !__version__! &mdash; <em>$Date: 2014-07-18 $</em>
 */
public class MRG2Random extends Random32 {

	private static final long serialVersionUID = 1L;

	public static final class Param implements Serializable {
		private static final long serialVersionUID = 1L;

		/**
		 * LEcuyer 1 parameters: a = 1498809829; b = 1160990996
		 */
		public static final Param LECUYER1 = new Param(1498809829, 1160990996);

		/**
		 * LEcuyer 2 parameters: a = 46325; b = 1084587
		 */
		public static final Param LECUYER2 = new Param(46325, 1084587);

		/**
		 * The default PRNG parameters: LECUYER1
		 */
		public static final Param DEFAULT = LECUYER1;

		public final int a;
		public final int b;

		public Param(final int a, final int b) {
			this.a = a;
			this.b = b;
 		}

		@Override
		public int hashCode() {
			return Hash.of(getClass())
				.and(a)
				.and(b).value();
		}

		@Override
		public boolean equals(final Object obj) {
			return Equality.of(this, obj).test(param ->
				eq(a, param.a) &&
				eq(b, param.b)
			);
		}

		@Override
		public String toString() {
			return format("Param[%d, %d", a, b);
		}
	}

	private static final class State implements Serializable {
		private static final long serialVersionUID = 1L;

		int r1;
		int r2;

		State(final long seed) {
			setSeed(seed);
		}

		State() {
			this(math.random.seed());
		}

		void setSeed(final long s) {
			long t = s%Integer.MAX_VALUE;
			if (t < 0) {
				t += Integer.MAX_VALUE;
			}

			r1 = (int)t;
			r2 = 1;
		}
	}

	private final Param _param;
	private final State _state;

	public MRG2Random(final Param param, final long seed) {
		_param = requireNonNull(param);
		_state = new State(seed);
	}

	public MRG2Random(final Param param) {
		this(param, math.random.seed());
	}

	public MRG2Random(final long seed) {
		this(Param.DEFAULT, seed);
	}

	public MRG2Random() {
		this(Param.DEFAULT, math.random.seed());
	}

	@Override
	public int nextInt() {
		step();
		return _state.r1;
	}

	public void step() {
		final long t = (long)_param.a*(long)_state.r1 +
						(long)_param.b*(long)_state.r2;

		_state.r2 = _state.r1;
		_state.r1 = (int)(t%Integer.MAX_VALUE); //int_math::modulo<modulus, 2>(t);
	}

	@Override
	public void setSeed(final long seed) {
		Optional.ofNullable(_state).ifPresent(s -> s.setSeed(seed));
	}

	public static void main(final String[] args) {
		final Random random = new MRG2Random(32344);
		for (int i = 0; i < 20; ++i) {
			System.out.println(random.nextInt());
		}
	}
}
<commit_msg>Fix random engine to produce full 32 bit integers.<commit_after>/*
 * Java Genetic Algorithm Library (@__identifier__@).
 * Copyright (c) @__year__@ <NAME>
 *
 * Licensed 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.
 *
 * Author:
 *    <NAME> (<EMAIL>)
 */
package org.jenetix.random;

import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
import static org.jenetics.internal.util.Equality.eq;

import java.io.Serializable;
import java.util.Random;

import org.jenetics.internal.util.Equality;
import org.jenetics.internal.util.Hash;

import org.jenetics.util.Random32;
import org.jenetics.util.math;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @since !__version__!
 * @version !__version__! &mdash; <em>$Date: 2014-07-19 $</em>
 */
public class MRG2Random extends Random32 {

	private static final long serialVersionUID = 1L;

	private static final long MODULUS = 0xFFFFFFFFL;

	public static final class Param implements Serializable {
		private static final long serialVersionUID = 1L;

		/**
		 * LEcuyer 1 parameters: a = 1498809829; b = 1160990996
		 */
		public static final Param LECUYER1 = new Param(1498809829, 1160990996);

		/**
		 * LEcuyer 2 parameters: a = 46325; b = 1084587
		 */
		public static final Param LECUYER2 = new Param(46325, 1084587);

		/**
		 * The default PRNG parameters: LECUYER1
		 */
		public static final Param DEFAULT = LECUYER1;

		public final long a;
		public final long b;

		public Param(final int a, final int b) {
			this.a = a;
			this.b = b;
 		}

		@Override
		public int hashCode() {
			return Hash.of(getClass())
				.and(a)
				.and(b).value();
		}

		@Override
		public boolean equals(final Object obj) {
			return Equality.of(this, obj).test(param ->
				eq(a, param.a) &&
				eq(b, param.b)
			);
		}

		@Override
		public String toString() {
			return format("Param[%d, %d", a, b);
		}
	}

	private static final class State implements Serializable {
		private static final long serialVersionUID = 1L;

		int r1;
		int r2;

		State(final long seed) {
			setSeed(seed);
		}

		void setSeed(final long seed) {
			long t = seed% MODULUS;
			if (t < 0) t += MODULUS;

			r1 = (int)t;
			r2 = 1;
		}
	}

	private final Param _param;
	private final State _state;

	public MRG2Random(final Param param, final long seed) {
		_param = requireNonNull(param);
		_state = new State(seed);
	}

	public MRG2Random(final Param param) {
		this(param, math.random.seed());
	}

	public MRG2Random(final long seed) {
		this(Param.DEFAULT, seed);
	}

	public MRG2Random() {
		this(Param.DEFAULT, math.random.seed());
	}

	@Override
	public int nextInt() {
		step();
		return _state.r1;
	}

	public void step() {
		final long t = _param.a*_state.r1 + _param.b*_state.r2;

		_state.r2 = _state.r1;
		_state.r1 = (int)(t% MODULUS);
	}

	@Override
	public void setSeed(final long seed) {
		if (_state != null) _state.setSeed(seed);
	}

	public static void main(final String[] args) {
		final Random random = new MRG2Random(32344);
		for (int i = 0; i < 20; ++i) {
			System.out.println(random.nextInt());
		}
	}
}

{'fraction_non_alphanumeric': 0.12293729372937294, 'fraction_numerical': 0.03217821782178218, 'mean_word_length': 3.4674447174447174, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4738532', 'n_tokens_mistral': 2842, 'n_tokens_neox': 2483, 'n_words': 740}