Switched PRNG to secure PRNG

This commit is contained in:
Paul Trudel 2023-04-17 19:35:02 +00:00
parent 643b0ecce8
commit 0528604839

View File

@ -1,17 +1,19 @@
package org.bigbluebutton.core.util
import java.security.SecureRandom
object RandomStringGenerator {
// From: http://www.bindschaedler.com/2012/04/07/elegant-random-string-generation-in-scala/
// Random generator
val random = new scala.util.Random
val random = new SecureRandom()
// Generate a random string of length n from the given alphabet
def randomString(alphabet: String)(n: Int): String =
Stream.continually(random.nextInt(alphabet.size)).map(alphabet).take(n).mkString
LazyList.continually(random.nextInt(alphabet.length)).map(alphabet).take(n).mkString
// Generate a random alphabnumeric string of length n
def randomAlphanumericString(n: Int) =
def randomAlphanumericString(n: Int): String =
randomString("abcdefghijklmnopqrstuvwxyz0123456789")(n)
}