Specifically, I just want to generate a cryptographically secure random number between 0 and some number x.
In OpenSSL this is done with the function
BigInteger(int bits, Random r)
As far as I can tell, this functionality is not provided. But it is easy enough to implement yourself.
Random r = new SecureRandom(); BigInteger q = something_big; BigInteger ans; do ans = BigInteger(bits_in_q, r); while (ans.compareTo(q) >= 0); // bn_rand_range generates numbers < q