September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
13
Task/Pick-random-element/Kotlin/pick-random-element.kotlin
Normal file
13
Task/Pick-random-element/Kotlin/pick-random-element.kotlin
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// version 1.0.6
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val list = listOf(1, 16, 3, 7, 17, 24, 34, 23, 11, 2)
|
||||
println("The list consists of the following numbers:")
|
||||
println(list)
|
||||
val chosen = mutableSetOf<Int>()
|
||||
println("\nFive elements chosen at random without duplication are:")
|
||||
while (chosen.size < 5) {
|
||||
val r = list[(Math.random() * list.size).toInt()]
|
||||
if (chosen.add(r)) println(r)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue