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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:59:49+00:00 2026-06-16T09:59:49+00:00

I need to generate random numbers, but from as wide a range as possible

  • 0

I need to generate random numbers, but from as wide a range as possible (64 bit at least). I don’t care if the distribution is perfect, so std::rand() would work, but it only returns an int. I understand that c++11 has some random number generating capability that can give any size number, but is very complex to use. Can someone post a simple example of how to use it as simply as possible to get the described functionality (64 bit or more random numbers) in as simple a way as possible (like std::rand())?

  • 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-16T09:59:51+00:00Added an answer on June 16, 2026 at 9:59 am

    This is how to use the C++11 random number generation for this purpose (adjusted from http://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution):

    #include <random>
    #include <iostream>
    int main()
    {
      /* Initialise. Do this once (not for every
         random number). */
      std::random_device rd;
      std::mt19937_64 gen(rd());
    
      /* This is where you define the number generator for unsigned long long: */
      std::uniform_int_distribution<unsigned long long> dis;
    
      /* A few random numbers: */    
      for (int n=0; n<10; ++n)
        std::cout << dis(gen) << ' ';
      std::cout << std::endl;
      return 0;
    }
    

    Instead of unsigned long long, you could use std::uintmax_t from cstdint to get the largest possible integer range (without using an actual big-integer library).

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

Sidebar

Related Questions

I need to generate random numbers from JavaScript within the Beta probability distribution .
I need to generate a lot of random numbers. I've tried using random.random but
I'm trying to generate random numbers from a gaussian distribution. Python has the very
I need to generate quickly lots of random numbers from binomial distributions for dramatically
I need to generate about 5,000 random numbers in my script, but the CPU
I need to generate a random number, but it needs to be selected from
Possible Duplicate: Generating random numbers effectively I need to generate random numbers in my
I need to generate a large list of random numbers from 600k to 2000k,
I need to generate random numbers that have a beta distribution in some speed
I need 100 random numbers from the range 1 to 1,000,000. The numbers must

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.