Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Lotto(){
- def Lotto(){
- val zahlen = (0 to 6).toList foldLeft (Nil : List[Int]) {
- (idx, vorher) =>
- var zufallsZahl = (Math.random*49 + 1).toInt
- while(vorher.contains(zufallsZahl)) {
- zufallsZahl = (Math.random*49 + 1).toInt
- } // solange neu würfeln, bis es in vorher diese zahl noch nicht gab.
- zufallsZahl :: vorher // anhängen
- }
- zahlen.foreach(println) // war: for (k <- 0 to 5) println(array(k))
- // oder:
- println(zahlen.mkString(" ")) // wenn du alle hintereinander haben willst.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement