<commit_before>val LOWERS = "abcdefghijklmnopqrstuvwxyz"
val UPPERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
val NUMS = "0123456789"
val SYMS = """`-=[]\;',./~!@#$%^&*()_+{}|:"<>?"""
val ALLCHARS = LOWERS + UPPERS + NUMS + SYMS

var len = 8
if (args.length > 0) {
  len = Integer.parseInt(args(0))
  if (args.length > 1 || len < 4) {
    println("usage: password <length>")
    sys.exit(1)
  }
}

val rand = new java.security.SecureRandom
(1 to 10).foreach { attempt =>
  val pw = (1 to len).map { i => ALLCHARS(rand.nextInt(ALLCHARS.length)) }.mkString("")
  val missing = Array(LOWERS, UPPERS, NUMS, SYMS).filter { group =>
    pw.filter { char => group.contains(char) }.isEmpty
  }
  if (missing.isEmpty) {
    println(pw)
    sys.exit(0)
  }
}

println("failed to find a good password")
sys.exit(1)
<commit_msg>rewrite as an object<commit_after>import java.security.SecureRandom

object Password {
  def generate(length: Int): String = {
    val Lowers = "abcdefghijklmnopqrstuvwxyz"
    val Uppers = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    val Digits = "0123456789"
    val Symbols = """`-=[]\;',./~!@#$%^&*()_+{}|:"<>?"""
    val Groups = Array(Lowers, Uppers, Digits, Symbols)
    val All = Groups.mkString("")

    val rand = new SecureRandom
    (1 to 100).foreach { attempt =>
      val result = (1 to length).map { i => All(rand.nextInt(All.length)) }.mkString("")
      val missing = Groups.filter { group => result.filter { c => group.contains(c) }.isEmpty }
      if (missing.isEmpty)
        return result
    }
    throw new Exception("failed to find a good password")
  }

  def main(args: Array[String]) {
    var length = 8
    if (args.length > 0) {
      length = Integer.parseInt(args(0))
      if (args.length > 1 || length < 4) {
        println("usage: password <length>")
        sys.exit(1)
      }
    }
    println(generate(length))
  }
}

{'fraction_non_alphanumeric': 0.17125877903835765, 'fraction_numerical': 0.023230686115613183, 'mean_word_length': 3.199546485260771, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '175565', 'n_tokens_mistral': 730, 'n_tokens_neox': 684, 'n_words': 160}