Commit 09393078 authored by Ilya Prokhorov's avatar Ilya Prokhorov

Random alphanumeric words generator

parent 318c5288
import scala.util.Random
import scala.collection.mutable.ListBuffer
class Generator {
def generateRandomString(wordsCount: Int, wordLength: Int): Array[String] = {
var wordsList = new ListBuffer[String]()
for(w <- 1 to wordsCount){
val string = Random.alphanumeric.take(wordLength).mkString("")
wordsList += string
}
return wordsList.toArray
}
}
object GeneratorApp {
def main(args: Array[String]): Unit = {
println(new Generator().generateRandomString(args(0).toInt, args(1).toInt).mkString("\n"))
}
}
scalac Generator.scala && scala GeneratorApp 3 8
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment