/*
This program generates random lottery numbers for:
- 6 distinct numbers out of 37
- 1 distinct number out of 7 (power number)
It uses:
- Kotlin's built‑in shuffled() for uniform random permutation
- Random.nextInt() for the single power number
- clean functions and idiomatic Kotlin style
*/
import kotlin.random.Random
/*
pickDistinctNumbers(count, max):
Returns `count` distinct random numbers from the range 1..max.
Algorithm:
- Build a list of all numbers 1..max
- Shuffle the list using shuffled()
- Take the first `count` numbers
This guarantees:
- all numbers are unique
- uniform randomness
- no duplicate checks needed
*/
fun pickDistinctNumbers(count: Int, max: Int): List<Int> {
return (1..max).toList()
.shuffled() // Fisher–Yates under the hood
.take(count)
}
/*
pickPowerNumber(max):
Returns a single random number in the range 1..max.
*/
fun pickPowerNumber(max: Int): Int {
return Random.nextInt(1, max + 1)
}
fun main() {
val mainCount = 6
val mainMax = 37
val powerMax = 7
// Generate main numbers (distinct)
val mainNumbers = pickDistinctNumbers(mainCount, mainMax).sorted()
// Generate power number
val powerNumber = pickPowerNumber(powerMax)
// Output results
println("Main numbers (6 out of 37): ${mainNumbers.joinToString(" ")}")
println("Power number (1 out of 7): $powerNumber")
}
/*
run:
Main numbers (6 out of 37): 1 20 21 22 25 35
Power number (1 out of 7): 5
*/