diff --git a/core-java-modules/core-java-numbers-7/src/test/java/com/baeldung/securerandompositivelong/SecureRandomPositiveLongUnitTest.java b/core-java-modules/core-java-numbers-7/src/test/java/com/baeldung/securerandompositivelong/SecureRandomPositiveLongUnitTest.java new file mode 100644 index 0000000000..b476a95d99 --- /dev/null +++ b/core-java-modules/core-java-numbers-7/src/test/java/com/baeldung/securerandompositivelong/SecureRandomPositiveLongUnitTest.java @@ -0,0 +1,24 @@ +package com.baeldung.securerandompositivelong; + +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; +import java.security.SecureRandom; + +import static org.assertj.core.api.Assertions.assertThat; + +public class SecureRandomPositiveLongUnitTest { + + @Test + void whenGenerateRecureRandom_thenGetExpectedValue() { + SecureRandom secureRandom = new SecureRandom(); + long randomPositiveLong = Math.abs(secureRandom.nextLong()); + + assertThat(randomPositiveLong).isPositive(); + + Double pc = 1.0 / Math.pow(2, 63); + System.out.printf("%.40f", pc); + + assertThat(pc).isLessThan(0.00000000000000001); + } +}