How to generate random numbers with equal probability

import acm.program.*;
import acm.util.*;
import java.lang.Math.*;
public class lol extends Program{
    public void run () {
        int end = readInt("Enter the last number that you want in the range(0, end), it will not be included, end: ");
        int flag = isPrime(end);
        if (flag == -1) {
            println("There is no prime numbers in this range");
        } else {
            println("Your prime number is: "+ flag);

    public RandomGenerator rgen=RandomGenerator.getInstance();

    public int isPrime(int n) {
        int temp = rgen.nextInt(n);
        for (int i = 2; i <= n; i++) {
            if(n % i == 0) {
                return temp;
        return -1;

I have to create a class that extends ACM’s RandomGenerator. It has to return a random prime number from a range which is specified by a user. Also these numbers on the given range have to appear with the same odds(for example if there are 4 primes in the range each one must appear with an odd of 25%).

How can this be achieved? (This is a test class not the one of the RandomGenerator)