All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.jqwik.engine.properties.arbitraries.randomized.BigUniformNumericGenerator Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
package net.jqwik.engine.properties.arbitraries.randomized;

import java.math.*;
import java.util.*;

import net.jqwik.api.*;

class BigUniformNumericGenerator implements RandomDistribution.RandomNumericGenerator {

	private final BigInteger min;
	private final BigInteger max;
	private final BigInteger range;
	private final int bits;

	BigUniformNumericGenerator(BigInteger min, BigInteger max) {
		this.min = min;
		this.max = max;
		this.range = max.subtract(min);
		this.bits = range.bitLength();
	}

	@Override
	public BigInteger next(Random random) {
		while (true) {
			BigInteger rawValue = new BigInteger(bits, random);
			BigInteger value = rawValue.add(min);
			if (value.compareTo(min) >= 0 && value.compareTo(max) <= 0) {
				return value;
			}
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy