Skip to content

Commit

Permalink
Use standard random API (#1988)
Browse files Browse the repository at this point in the history
* Use standard random API
* Inline 'random' method
  • Loading branch information
turansky authored May 6, 2020
1 parent de38890 commit 18f68ad
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions js/example-frontend-js/src/ExampleMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.w3c.dom.*
import kotlin.browser.*
import kotlin.coroutines.*
import kotlin.math.*
import kotlin.random.Random

fun main() {
println("Starting example application...")
Expand All @@ -35,9 +36,6 @@ private fun HTMLElement.setPosition(x: Double, y: Double) {
}
}

@Suppress("DEPRECATION")
private fun random() = kotlin.js.Math.random()

class Application : CoroutineScope {
private val body get() = document.body!!
private val scene get() = document.getElementById("scene") as HTMLElement
Expand Down Expand Up @@ -125,7 +123,7 @@ class Application : CoroutineScope {
timer.delay(1000) // pause a bit
// flip direction
val t = vx
if (random() > 0.5) {
if (Random.nextDouble() > 0.5) {
vx = vy
vy = -t
} else {
Expand All @@ -150,11 +148,11 @@ class Application : CoroutineScope {
animation("circle", radius) { circle ->
println("Started new 'circle' coroutine #$index")
val timer = AnimationTimer()
val initialAngle = random() * 2 * PI
val initialAngle = Random.nextDouble() * 2 * PI
var vx = sin(initialAngle) * initialSpeed
var vy = cos(initialAngle) * initialSpeed
var x = (random() * initialRange + (1 - initialRange) / 2) * sw
var y = (random() * initialRange + (1 - initialRange) / 2) * sh
var x = (Random.nextDouble() * initialRange + (1 - initialRange) / 2) * sw
var y = (Random.nextDouble() * initialRange + (1 - initialRange) / 2) * sh
while (true) {
val dt = timer.await()
val dx = sw / 2 - x
Expand Down

0 comments on commit 18f68ad

Please sign in to comment.