samedi 27 juin 2020

How to select a random line from a .txt file in Kotlin

I want to create a program that randomly prints out a line from a .txt file. This is what I'm currently at, and the only other similar questions I could find were in other languages. For example, Python with the random.choice() operation, which I found in this question: How to choose a random line from a text file

Thank you all for your time!

import kotlin.system.exitProcess

fun main() {
    val file = "text.txt"
    println(file.random("text.txt")) //This code doesn't work, I'm just illustrating what I was looking to do.
}



Aucun commentaire:

Enregistrer un commentaire