public Double relativePrime(Double x) {
        ArrayList<Double> primes = new ArrayList<Double>();
        Double relativePrime = BigInteger.probablePrime(9, new Random()).doubleValue();
        while (relativePrime<x) {
            if (BigInteger.valueOf(x.longValue()).gcd(BigInteger.valueOf(relativePrime.longValue())).intValue() == 1) {
                relativePrime = Math.pow(relativePrime, Math.floor((Math.random()*2)+1));
                if (relativePrime < x) {
                    return relativePrime;
                }
            }
            relativePrime = BigInteger.probablePrime(9, new Random()).doubleValue();
        }    
        return relativePrime;
    }