Skip to content

Instantly share code, notes, and snippets.

@leontabak
Created September 29, 2021 15:12
Show Gist options
  • Save leontabak/19e4683dd6ab79b1d8bdb7ad0ed25e47 to your computer and use it in GitHub Desktop.
Save leontabak/19e4683dd6ab79b1d8bdb7ad0ed25e47 to your computer and use it in GitHub Desktop.
how to fill a list with objects whose properties have random values
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