Check out example codes for "random java". It will help you in understanding the concepts better.

Code Example 1

import java.util.Random();
Random <name> = new Random();
<variable> = <name>.nextInt(<excuslive top limit>);

Code Example 2

public class GuessTheNumber {
  public static void main(String[] args) {
    
    
    int randomInt = (int)(20.0 * Math.random());
    int num1 = randomInt;
    int num2 = 10;
    
    if(num1 == num2){
    	System.out.println("Correct!");
    } else if(num1 > num2){
    	System.out.println("Too low!");
    } else{
    	System.out.println("Too high!");
    }
    
    
  }
}

Code Example 3

import java.util.Arrays;

public class HelloWorld {
  public static void main(String[] args) {
    
    // init array
    String[] family = new String[] {"Nova", "Mpo", "Moms", "Shorty", "Charlie"};
    
    // print array string
    System.out.println(Arrays.toString(family));
    
 
  }
}

Code Example 4

public class HelloWorld {
  public static void main(String[] args) {
    
    
    // triangular number - first 10
    int x = 1;
    int triangularNumber = 1;
    
    
    while(x < 10)
    {
    
    	System.out.println(triangularNumber);
    	
    	x++;
    	
    	triangularNumber = triangularNumber + x;
    }
    
    
 
  }
}

Code Example 5

package com.example.guessthenumber;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import java.util.Random;

public class MainActivity extends AppCompatActivity {


    int randomNumber;

    public void generateRandomNumber(){

        Random rand = new Random();
        randomNumber = rand.nextInt(20) + 1;

    }

    public void GuessTheNumber(View view){


        EditText numberET = (EditText) findViewById(R.id.numerEditText);

        int guessValue = Integer.parseInt(numberET.getText().toString());

        String message;

        if(guessValue > randomNumber)
        {
            message = "Lower!";
        }
        else if (guessValue < randomNumber)
        {
            message = "Higher!";
        }
        else
        {
            message = "Good Guess!!!  Try Again";

            generateRandomNumber();
        }

        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();

        Log.i("Entered Text", numberET.getText().toString());

        Log.i("Random Number", Integer.toString(randomNumber));

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        generateRandomNumber();

    }
}

Learn ReactJs, React Native from akashmittal.com