Skip to content

Commit

Permalink
replacing Math.random with SecureRandom (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndduc01 authored Sep 6, 2024
1 parent 83fedaf commit 72db5df
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.sql.Date;

public class RandomValueGenerator {
private static final SecureRandom secureRandom = new SecureRandom();

public static String getRandomString(SecureRandom random) {
int length = random.nextInt(10) + 1; // FLAG
StringBuilder sb = new StringBuilder(length);
Expand All @@ -16,7 +18,7 @@ public static String getRandomString(SecureRandom random) {
public static Date getRandomDate() {
long beginTime = Date.valueOf("2000-01-01").getTime();
long endTime = Date.valueOf("2020-12-31").getTime();
long randomTime = beginTime + (long) (Math.random() * (endTime - beginTime)); // FLAG
long randomTime = beginTime + (long) (secureRandom.nextDouble() * (endTime - beginTime));
return new Date(randomTime);
}

Expand Down

0 comments on commit 72db5df

Please sign in to comment.