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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:09:30+00:00 2026-06-13T05:09:30+00:00

I want the random number generation to be controllable with a variable. For example,

  • 0

I want the random number generation to be controllable with a variable. For example, if I say 100, numbers should be generated with maximum randomness, and if I say 50, the numbers should not be ‘as random’. If I say ‘0’, possibly the random numbers should not be random at all – maybe all numbers generated are same.

Any idea what I can use to generate controlled random numbers like these? Any idea if some C++ inbuilt library, or maybe Boost library does this?

It will be good to have a way to regenerate the same sequence of random numbers, so a way to seed the generator would also be good.

  • 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-13T05:09:31+00:00Added an answer on June 13, 2026 at 5:09 am

    The way you describe your requirement seems to suggest that using a normal distribution (aka Gaussian distribution) may be the way to go. It has two parameters: Mean and standard deviation. If you set the standard deviation very low, you get random values that are probably quite close to the mean. If you set it to a large value, you get them distributed more widely.

    In C++11 a normal distribution is available from the standard library. If C++11 is not an option for you, the Boost library has it, too.

    Here is some example code:

    #include <iostream>
    #include <iomanip>
    #include <string>
    #include <map>
    #include <random>
    #include <cmath>
    #include <iomanip>
    
    int main()
    {
      std::random_device rd;
      std::mt19937 gen(rd());
    
      std::cout << std::fixed << std::setprecision(3);
    
      /* Mean 5, standard deviation very low (0.002): */
      std::normal_distribution<> d1(5,0.002);
      for (int i = 0 ; i < 20 ; ++i)
        std::cout << std::setw(7) << d1(gen) << "  ";
      std::cout << std::endl;
    
      /* Mean 5, standard deviation relatively high (2.0): */
      std::normal_distribution<> d2(5,2);
      for (int i = 0 ; i < 20 ; ++i)
        std::cout << std::setw(7) << d2(gen) << "  ";
      std::cout << std::endl;
    
      return 0;
    }
    

    Here is the output:

    4.998    5.003    5.001    5.002    5.001    5.001    4.998    5.000    4.999    5.001    5.000    5.003    4.999    5.000    5.001    4.998    5.000    4.999    4.996    5.001  
    2.781    3.795    5.669   -0.109    7.831    3.302    3.823    4.439    4.672    4.461    6.626    5.139    6.882    5.406    6.526    5.831    6.759    2.627    3.918    4.617
    

    As you can see, in the first row all numbers are quite close to 5 (i.e., to use your wording, “randomness” is low), while in the second row the numbers are spread much more widely.

    (EDIT: Of course, the randomness of these numbers isn’t really affected. It’s just that the standard deviation parameter makes the values more likely to emerge in a smaller (stddev low) or wider (stddev high) range of numbers.)

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

Sidebar

Related Questions

I want to get N random numbers whose sum is a value. For example,
I want to add 100 entry to users table numbers field, random characters length
I want to repeat a random number sequence generated by a legacy software using
Is this how PHP implemented random number generating? Say I want to calculate a
Duplicate: Unique random numbers in O(1)? I want an pseudo random number generator that
I want to use a random number generator that creates random numbers in a
I have a byte array generated by a random number generator. I want to
All I want is a pragmatic random number generator in C# so I can
I'm generating a number of circles with random positions. what I want to prevent
I want to know how to get a 4-digit random number in Java. I

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.