Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,788 questions

51,694 answers

573 users

How to generate random floating point numbers in Kotlin

1 Answer

0 votes
import kotlin.random.Random

fun generateRandomNumbers(n: Int, lower: Double, upper: Double): List<Double> {
    return List(n) { lower + (upper - lower) * Random.nextDouble() }
}

fun main() {
    val n = 10
    val lower = 0.0
    val upper = 3.0

    val randomNumbers = generateRandomNumbers(n, lower, upper)

    println(randomNumbers.joinToString(" ") { String.format("%.6f", it) })
}


/*
run:

1.252009 1.494544 1.229563 2.306142 0.992433 0.050440 2.077199 1.949221 0.382566 2.402671

*/

 



answered Nov 3, 2025 by avibootz
...