Skip to content

Commit

Permalink
Best practices for SecureRandom as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacl committed Sep 12, 2024
1 parent b95b9eb commit d526674
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lila/src/main/scala/Random.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package scalalib

import scala.collection.mutable.StringBuilder

private final val store =
private final val regStore =
java.lang.ThreadLocal.withInitial(() => RandomApi(java.util.concurrent.ThreadLocalRandom.current))

def ThreadLocalRandom = store.get
def ThreadLocalRandom = regStore.get

val SecureRandom = RandomApi(java.security.SecureRandom())
private final val secureStore =
java.lang.ThreadLocal.withInitial(() => RandomApi(java.security.SecureRandom()))

def SecureRandom = secureStore.get

final class RandomApi(impl: java.util.Random):

Expand Down

0 comments on commit d526674

Please sign in to comment.