How do u get a random number in Kotlin | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do u get a random number in Kotlin

Using java.util.Random or any other method

13th Sep 2020, 5:54 PM
dign_code
dign_code - avatar
6 Answers
+ 7
fun main(args: Array<String>) { val random = java.util.Random(); var test = "ABCDEFGH" var num = random.nextInt(test.length);//(7) println(num) println(test[num]) }
13th Sep 2020, 6:20 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 5
I have been extending the Kotlin course. This is my Random lesson. https://www.sololearn.com/post/529872
17th Sep 2020, 2:41 AM
John Wells
John Wells - avatar
+ 2
kotlin can use the java libraries.
13th Sep 2020, 7:08 PM
Oma Falk
Oma Falk - avatar
+ 2
Just found out. Thanks everyone for your help
18th Sep 2020, 8:31 PM
dign_code
dign_code - avatar
+ 1
Just add the limit of the randomness you want it to reach https://code.sololearn.com/c5Dt7z7w9M5c/?ref=app
18th Sep 2020, 8:30 PM
dign_code
dign_code - avatar
+ 1
Rik Wittkopp isn't my answer nice Check out the code
18th Sep 2020, 8:32 PM
dign_code
dign_code - avatar