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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:56:00+00:00 2026-06-03T21:56:00+00:00

generate(vec.begin(), vec.end(), [=](){return static_cast<T>(static_cast<double>(ran()) /RAND_MAX*(max-min)+min); }); Problem: RAND_MAX*(max-min)+min); Ok, so I know the algorithms,

  • 0
generate(vec.begin(), vec.end(), [=](){return static_cast<T>(static_cast<double>(ran())
/RAND_MAX*(max-min)+min); });

Problem: RAND_MAX*(max-min)+min);

Ok, so I know the algorithms, lambda expressions, and, capture clause in this thing. My question is quite ridiculous to all of that. What is the bolded text above mean. I mean, I know its part of the random value generation process. But don’t know exactly what the hell is going on. So can someone pls break down that tinny tiny little code.

  • 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-03T21:56:01+00:00Added an answer on June 3, 2026 at 9:56 pm

    static_cast<double>(ran())/RAND_MAX*(max-min)+min);

    I’m assuming you mistyped rand(), which returns a pseudorandom integer from 0 to RAND_MAX. Let’s rewrite that in a way that clarifies the precedence a bit:

    (T) ( (((double) rand() / RAND_MAX) * (max-min) ) + min

    So what it does is:

    1. rand(): take a random integer between 0 and RAND_MAX
    2. (double) / RAND_MAX: divide as double by RAND_MAX, yielding a uniformly distributed double between 0 and 1:
    3. * (max-min): multiply by the range (max-min), yielding a double from 0 to (max-min)
    4. +min: add the minimum to yield a random double between min and max
    5. static_cast<T>: cast it back to the original type

    The result is a uniformly distributed random number of type T between min and max.

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

Sidebar

Related Questions

I generate some Excel file with Microsoft Interop, no problem, I can create files,
I generate a *.csv file with PHP and it works great. The problem is,
Generate a random string of any particular length. I know this question has been
I generate a XMLDocument based on a dataset by binding the dataset to the
We generate pdf files with data regarding monthly financial balance of tens of thousands
I generate csv files with fputcsv and it works just fine, but when I
I generate a figure in MATLAB with large amount of elements (100000+) and want
I generate a dynamic assembly with CSharpCodeProvider, from a C# source saved into a
I generate some code using CXF from a WSDL-file. When compiling the code with
I generate a certification key with openssl. Here is my command: openssl genrsa -des3

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.