Skip to content

Commit

Permalink
delete
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-aws committed Nov 6, 2023
1 parent 51f1047 commit 28f559e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 44 deletions.
20 changes: 7 additions & 13 deletions src/interop/java/DRandomUniform.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,30 @@
package Uniform_mImplementation;
package UniformPowerOfTwo_mImplementation;

import java.security.SecureRandom;
import java.math.BigInteger;
import java.lang.Thread;

public final class DRandomUniform {

private static final ThreadLocal<SecureRandom> RNG = ThreadLocal.withInitial(DRandomUniform::createSecureRandom);

private DRandomUniform() {} // Prevent instantiation

private static final SecureRandom createSecureRandom() {
private static final SecureRandom createSecureRandom() {
final SecureRandom rng = new SecureRandom();
// Required for proper initialization
rng.nextBoolean();
return rng;
}

/**
* Sample a uniform value using rejection sampling between [0, n).
*
* @param n an integer (must be >= 1)
* @return a uniform value between 0 and n-1
* @throws IllegalArgumentException if `n` is less than 1
*/
public static BigInteger Uniform(final BigInteger n) {
public static BigInteger UniformPowerOfTwo(BigInteger n) {
if (n.compareTo(BigInteger.ONE) < 0) {
throw new IllegalArgumentException("n must be positive");
}

BigInteger sampleValue;
do {
sampleValue = new BigInteger(n.bitLength(), RNG.get());
} while (sampleValue.compareTo(n) >= 0);

sampleValue = new BigInteger(n.bitLength(), RNG.get());

return sampleValue;
}
Expand Down
31 changes: 0 additions & 31 deletions src/interop/java/DRandomUniformPowerOfTwo.java

This file was deleted.

0 comments on commit 28f559e

Please sign in to comment.