java find a biginteger within specific range
<p>Im developing an application with java which needs to find two big integers (Y and Z) that  meet this two conditions:</p>

<pre><code>Y^k &lt; N  and Z^j &lt; N &lt; Z^(j+1)
</code></pre>

<p>N, k and j are known. N is a big integer(1024bit). </p>

<p>My current implementations finds Y and Z by choosing a random BigInteger and tests if the conditions are met. But the problem is that sometimes it takes really long to find the solution or it doesn't find one at all (probably the bitSize isn't correctly computed). 
Is there any way i could speed this up?</p>

<p>The code:</p>

<pre><code>BigInteger getMessage(int bitSize, int lowerBound, int upperBound, BigInteger module)
{
        boolean foundOne = false;
        BigInteger candidate = null;
        while( !foundOne )
        {
                candidate = new BigInteger(bitSize,random);
                foundOne = (upperBound == 0 || candidate.pow(upperBound).compareTo(module) &gt; 0 ) &amp;&amp; (lowerBound == 0 || candidate.pow(lowerBound).compareTo(module) &lt; 0);
        }

        return candidate;
}
</code></pre>
