Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8282559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:24:44+00:00 2026-06-08T10:24:44+00:00

Specifically, I just want to generate a cryptographically secure random number between 0 and

  • 0

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 bn_range.

I can implement it myself using Java’s BigInteger(int bits, Random r) constructor (which generates a number from 0 to 2bits). But I would like, if possible, to use a better tested algorithm for the sake of security.

Is there a standard way to do this in Java?

P.S. I am actually using Android, but I don’t know how to do it in standard Java.

EDIT: x is a large integer stored as a BigInteger.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:24:46+00:00Added an answer on June 8, 2026 at 10:24 am

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with the jQuery ColorPicker widget - specifically exercising the ColorPickerSetColor function (just
I want to restyle just part of a WPF control. (Specifically, I want to
Specifically, I just want to record something, reverse it, and play it back. I've
This question is pretty straight forward, I literally just want to stream video of
How can I specifically override just the back button while within a dialog to
Just a quick question about ReadWriteLocks in Java (specifically the ReentrantReadWriteLock implementation) as I
Specifically I am trying to open a file from SharePoint, but it's really just
Specifically I am interested for the LAMP Stack and some of the best practices
This may seem obvious to most people, but I'm just trying to confirm that
I'm having some trouble understanding access modifiers; I want to know better when to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.