@@ -11,6 +11,7 @@ import org.w3c.dom.*
1111import kotlin.browser.*
1212import kotlin.coroutines.*
1313import kotlin.math.*
14+ import kotlin.random.Random
1415
1516fun main () {
1617 println (" Starting example application..." )
@@ -35,9 +36,6 @@ private fun HTMLElement.setPosition(x: Double, y: Double) {
3536 }
3637}
3738
38- @Suppress(" DEPRECATION" )
39- private fun random () = kotlin.js.Math .random()
40-
4139class Application : CoroutineScope {
4240 private val body get() = document.body!!
4341 private val scene get() = document.getElementById(" scene" ) as HTMLElement
@@ -125,7 +123,7 @@ class Application : CoroutineScope {
125123 timer.delay(1000 ) // pause a bit
126124 // flip direction
127125 val t = vx
128- if (random () > 0.5 ) {
126+ if (Random .nextDouble () > 0.5 ) {
129127 vx = vy
130128 vy = - t
131129 } else {
@@ -150,11 +148,11 @@ class Application : CoroutineScope {
150148 animation(" circle" , radius) { circle ->
151149 println (" Started new 'circle' coroutine #$index " )
152150 val timer = AnimationTimer ()
153- val initialAngle = random () * 2 * PI
151+ val initialAngle = Random .nextDouble () * 2 * PI
154152 var vx = sin(initialAngle) * initialSpeed
155153 var vy = cos(initialAngle) * initialSpeed
156- var x = (random () * initialRange + (1 - initialRange) / 2 ) * sw
157- var y = (random () * initialRange + (1 - initialRange) / 2 ) * sh
154+ var x = (Random .nextDouble () * initialRange + (1 - initialRange) / 2 ) * sw
155+ var y = (Random .nextDouble () * initialRange + (1 - initialRange) / 2 ) * sh
158156 while (true ) {
159157 val dt = timer.await()
160158 val dx = sw / 2 - x
0 commit comments