   Don't know how to use Rand()
  I have been having quite a few troubles using rand.I'm using it to generate a number beetween two integers. The problem Is that the number goes put of the range. I don't reall know to use rand properlly, could someone explain it?   
C++ reference to the rescue!   ;  I read that, the part that confuses me is this line( value % 30 + 1985 ) is in the range 1985 to 2014it doesn't seem right;  rand()%30 returns a random value between 0 and 29, by nature of the modulo operator; adding 1985 yields the range 0+1985 = 1985 to 29+1985 = 2014.  Therefore, a random number between A and B (inclusively) is:  rand()%(B-A+1)+AIf A is 1, and B is 5, then (B-A+1) is 5.  rand()%5 is a number in the range of [0, 4], then add A; the result is a number in the range [1, 5] therefore rand()%(B-A+1)+A returns a number in the set [A, B]   ;  I think the part that is confusing you is because range starts at 0 and not 1 so if you wanted to do 1 - 100 you would do 100 + 1. For 1985 + range 30 well that is actually between 0 - 29, does this help you?*EDIT: _Fastcall beat me to it... lol   ;  Moving to General Programming.   ;  But note that depending on the implementation of rand(), uniform distribution can often not be reached through the modulus operator:namespace foo {   // A bad linear congruential generator   const unsigned int rand_max = 1024;   unsigned int rand () { static const unsigned int    a = 69069, c = 1, m = rand_max; static unsigned int state; state = (a * state + c) % m; return state;   }}#include <vector>#include <iostream>int main() {   const unsigned int buckets = 15;   std::vector<unsigned int> mod(buckets);   std::vector<unsigned int> uni(buckets);   for (unsigned int i=0; i<0xFFFFFF; ++i) { const unsigned int r = foo::rand()%buckets; mod[r]++;   }   for (unsigned int i=0; i<0xFFFFFF; ++i) { const unsigned int r = buckets * (foo::rand() / (float)(foo::rand_max)); uni[r]++;   }   for (unsigned int i=0; i<buckets; ++i) { std::cout << "mod[" << i << "] = " << mod << '\n';   }   std::cout << "--\n";   for (unsigned int i=0; i<buckets; ++i) { std::cout << "uni[" << i << "] = " << uni << '\n';   }   return 0;}Output:mod[0] = 1130495mod[1] = 1130496mod[2] = 1130496mod[3] = 1130496mod[4] = 1114112mod[5] = 1114112mod[6] = 1114112mod[7] = 1114112mod[8] = 1114112mod[9] = 1114112mod[10] = 1114112mod[11] = 1114112mod[12] = 1114112mod[13] = 1114112mod[14] = 1114112--uni[0] = 1130496uni[1] = 1114112uni[2] = 1114112uni[3] = 1130495uni[4] = 1114112uni[5] = 1114112uni[6] = 1114112uni[7] = 1130496uni[8] = 1114112uni[9] = 1114112uni[10] = 1114112uni[11] = 1130496uni[12] = 1114112uni[13] = 1114112uni[14] = 1114112Both are not perfect, but in many monte carlo situations, the first one (mod) would yield worse results than the second one.   