Skip to content

Commit 72e4ae4

Browse files
authored
Java Supplier API (#145)
By submitting this pull request, I confirm that my contribution is made under the terms of the [MIT license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).
1 parent 6ffd98a commit 72e4ae4

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

docs/java/BuildTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static void main(String[] args) {
7070
System.out.println("\nCUSTOM RNG TESTS\n");
7171

7272
SecureRandom rng = new SecureRandom();
73-
DafnyVMC.Random t = new DafnyVMC.Random(rng);
73+
DafnyVMC.Random t = new DafnyVMC.Random(() -> rng);
7474

7575
System.out.println("Example of Coin sampling");
7676
System.out.println(t.CoinSample());

src/interop/java/Full/Random.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import dafny.TypeDescriptor;
44
import java.math.BigInteger;
55
import java.security.SecureRandom;
6+
import java.util.function.Supplier;
67

78
public class Random implements DafnyVMCTrait.RandomTrait {
89
static ThreadLocal<SecureRandom> rng;
@@ -11,8 +12,8 @@ public Random() {
1112
this.rng = ThreadLocal.withInitial(Random::createSecureRandom);
1213
}
1314

14-
public Random(SecureRandom rng) {
15-
this.rng = ThreadLocal.withInitial(() -> rng);
15+
public Random(Supplier<SecureRandom> supplier) {
16+
this.rng = ThreadLocal.withInitial(supplier);
1617
}
1718

1819
private static final SecureRandom createSecureRandom() {

0 commit comments

Comments
 (0)