Hi how can you generate a random int between 0 and 10 in kotlin ? I tried Random().nextInt()
and val rnds = (0..10).random()
but i can't generate one. Thanks
Asked
Active
Viewed 7,271 times
0

Jats1596
- 1,117
- 1
- 13
- 20
-
Which Kotlin version? (0..10).random() works for >= 1.3 – pedro_bb7 Dec 13 '19 at 02:12
-
Please post code, otherwise we have no idea what the issue is. Also, what do you mean by 'you can't generate one'? Whats your code even doing then? – Frontear Dec 13 '19 at 02:22
-
`val r = (0..10).random()` as given in the other post. – Mahozad May 07 '22 at 06:12
1 Answers
2
To generate random number you can do as follow:
val randomNumber: Int = Random().nextInt(10) // here you can set your own bound value. This will give you random number from 0 to 10

Nik
- 1,991
- 2
- 13
- 30