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 8322711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:28:41+00:00 2026-06-08T23:28:41+00:00

In java random number can get like protected final static Random RANDOM = new

  • 0

In java random number can get like

protected final static Random RANDOM = new Random(System.currentTimeMillis()); 

In c++ using GMP Library how it possible to generate random number?

I used code like

    gmp_randstate_t s;
unsigned long seed;
seed = time(NULL); 
gmp_randinit_default(s);
gmp_randseed_ui(s, seed);

mpz_class ran;
gmp_randclass rr(s);
ran =rr.get_z_bits(125);
long int random=ran.get_ui();

But i dont get random number.

Please help me.

  • 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-08T23:28:42+00:00Added an answer on June 8, 2026 at 11:28 pm

    First, there is no gmp_randclass constructor that takes a gmp_randstate instance, so your code didn’t compile for me. The recommended way to construct a gmp_randclass instance is using gmp_randinit_default, like this:

    gmp_randclass rr(gmp_randinit_default);
    

    The first part of your code is seeding the gmp_randstate_t s, but that random state variable s is not used in the second part of your code (after the above change). Unless seeded otherwise, the default GMP random number generator always starts with the same seed, which means the same sequence of random numbers will be generated each time you run the program. You can seed an instance of gmp_randclass using the gmp_randclass::seed function.

    The following code is similar to yours but seeds the random number generator based on the current time.

    mpz_class ran;
    gmp_randclass rr(gmp_randinit_default);
    rr.seed(time(NULL));
    ran =rr.get_z_bits(125);
    long int random=ran.get_ui();
    

    Note that as discussed in Random State Seeding, using a low-resolution current time is usually a poor choice for a random number generator seed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I generate a random number in Java using different distributions within a
I want to know how to get a 4-digit random number in Java. I
Is it possible to generate the same random number in python as in java
I am trying to make a Java implementation of the Park-Miller-Carta PRNG random number
I'm using Java to parse HTML from a random website, let's say it's http://google.com
Possible Duplicate: Java: generating random number in a range I want to generate a
I am creating random number generator in Java as part of program I am
I'm looking for a random number generator in JavaScript which I can initialize with
Using Javascript, how can I generate random numbers that are skewed towards one end
Possible Duplicate: Java: generating random number in a range I want to generate random

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.