-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add edit checks to ensure that when using Random it always gives a non zero value
- Loading branch information
1 parent
7180ae4
commit b3e1f8e
Showing
6 changed files
with
33 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package test.support; | ||
|
||
import java.security.SecureRandom; | ||
import java.util.Random; | ||
|
||
public final class SafeRandoms { | ||
|
||
private static final Random random = new SecureRandom(); | ||
|
||
private SafeRandoms() {} | ||
|
||
public static int nextInt(int bound) { | ||
return nextInt(random, bound); | ||
} | ||
|
||
public static int nextInt(Random random, int bound) { | ||
int value = 0; | ||
while (value == 0) { | ||
value = random.nextInt(bound); | ||
} | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters