import scala.util.Random def tetrominos(amount: Int, bag: List[Char] = Nil): List[Char] = { val actualBag = if (bag.nonEmpty) bag else List('L', 'J', 'S', 'Z', 'T', 'O', 'I') val index = Random.nextInt(actualBag.size) actualBag(index) :: (amount match { case 0 => Nil case _ => tetrominos(amount - 1, actualBag.patch(index, Nil, 1)) }) } print(tetrominos(50).mkString)