Created
September 29, 2021 15:12
-
-
Save leontabak/19e4683dd6ab79b1d8bdb7ad0ed25e47 to your computer and use it in GitHub Desktop.
how to fill a list with objects whose properties have random values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Process( val x0:Double, val x1:Double ) | |
fun main() { | |
// create random number generator | |
val rng = kotlin.random.Random(System.nanoTime()) | |
val elementInitializer: (Int) -> Process = | |
{_:Int -> Process(rng.nextDouble(), rng.nextDouble())} | |
val queue = List<Process>(12, elementInitializer) | |
for( p in queue ) { | |
println( p ) | |
} // for | |
} // main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment