Created
March 31, 2023 07:59
-
-
Save LDuncAndroid/85abb9b5e463b2d7dcbbfec78bd6c2e6 to your computer and use it in GitHub Desktop.
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
import kotlin.random.Random | |
import kotlin.random.nextInt | |
// https://stackoverflow.com/posts/69076855/revisions @aSemy | |
val randomInts = generateSequence { | |
// this lambda is the source of the sequence's values | |
Random.nextInt(1..69) | |
} | |
// make the values distinct, so there's no repeated ints | |
.distinct() | |
// only fetch 6 values | |
// Note: It's very important that the source lambda can provide | |
// this many distinct values! If not, the stream will | |
// hang, endlessly waiting for more unique values. | |
.take(6) | |
// sort the values | |
.sorted() | |
// and collect them into a Set | |
.toSet() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment