In the following code, how RAND_MAX works and how the poisson distribution value generated???
what will be the value of RAND_MAX in following code??

long poisson(double lambda)
{
  double u = double(rand()) / RAND_MAX;
  long k = 0;
  double currentprob;

  while (u >= (currentprob = pow(lambda,k) * exp(-lambda) 
           / factorial(k)))
    {
      u -= currentprob;
      k++;
    }

  return k;
}

RAND_MAX is a constant defined by your implementation ( i.e. it is defined by what compiler are you using on what platform) is a large number but it is at least 32767(it may be greater depending on your implementation)
rand() function generates a random integer between 0 and RAND_MAX
For more :http://www.cplusplus.com/reference/clibrary/cstdlib/rand/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.