In Kotlin I would like to select a random value between 0 and 10 but at the same time specify a value that should not be selected. For example if I specify not to select the number 5, it will skip this value and choose only from the other values.
I can easily code this but it would probably be more than 3 lines of code. I'm wondering if there is a simple and shorter way.
You could generate a sequence of numbers in the range you care about and take the first one that is not one of the ones you don't care about...
sequence<Int> { (1.. 10).random() }.first { it != 5 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With