== How to fix it in Java SE

=== Code examples
The following code uses a cryptographically strong random number generator to generate data that is not cryptographically strong.

==== Noncompliant code example

[source,kotlin,diff-id=1,diff-type=noncompliant]
----
import java.security.SecureRandom

val sr = SecureRandom()
sr.setSeed(123456L) // Noncompliant
val v = sr.nextInt()
----

[source,kotlin,diff-id=2,diff-type=noncompliant]
----
import java.security.SecureRandom

val sr = SecureRandom("abcdefghijklmnop".toByteArray(charset("us-ascii"))) // Noncompliant
val v = sr.nextInt()
----

==== Compliant solution

[source,kotlin,diff-id=1,diff-type=compliant]
----
import java.security.SecureRandom

val sr = SecureRandom()
val v = sr.nextInt()
----

This solution is available for JDK 1.8 and higher.
[source,kotlin,diff-id=2,diff-type=compliant]
----
import java.security.SecureRandom

val sr = SecureRandom.getInstanceStrong()
val v = sr.nextInt()
----

include::../../common/how-does-it-work.adoc[]
