when ((0..3).random()) {
          0 -> {
          //write code here.
          }
          1 -> {
          //write code here.
          }
          2 -> {
          //write code here.
          }
          3 -> {
          //write code here.
          }
        }

      Kotlin language logo
      Random Number

      Kotlin recipes

      The code uses the when keyword to create a conditional block. It first randomly selects an integer between 0 and 3, and then sets the code block to that value.

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.