Last active
February 3, 2026 20:25
-
-
Save dacr/15a45f5f67dcb57e61b84f8a5c0b766c to your computer and use it in GitHub Desktop.
generate a random euromillions play / published by https://github.com/dacr/code-examples-manager #182068a4-970a-4ca0-bccb-f41fa2d44d31/696310157cd66fdd79f72cedbea7f3244b66a6c6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // summary : generate a random euromillions play | |
| // keywords : scala, euromillions, random, rng, fdj, @testable | |
| // publish : gist | |
| // authors : David Crosson | |
| // license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // id : 182068a4-970a-4ca0-bccb-f41fa2d44d31 | |
| // created-on : 2021-02-10T21:45:49Z | |
| // managed-by : https://github.com/dacr/code-examples-manager | |
| // run-with : scala-cli $file | |
| // --------------------- | |
| //> using scala "3.6.4" | |
| // --------------------- | |
| def gen(limit:Int):Int = scala.util.Random.nextInt(limit)+1 | |
| def select(limit:Int,count:Int):List[Int]= { | |
| LazyList | |
| .continually(gen(limit)) | |
| .scanLeft(Set.empty[Int]) ( (selected, randomlyChosen) => selected+randomlyChosen) | |
| .find(_.size == count) | |
| .get | |
| .toList | |
| .sorted | |
| } | |
| println("nums : " + select(50,5).mkString(" - ")) | |
| println("stars : " + select(12,2).mkString(" - ")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment