MATLAB rand and C++ rand()
It is a programming question, not a signal processing question - keep that in mind, and next time use the StackOverflow.


MATLAB rand function returns uniformly distributed variable on interval $[0,1]$.
C++ rand function returns integer between 0 and RAND_MAX, additionally it is not very 'random' function. You would also have to normalize its output. For more info please refer here: C++ rand() between 0 and 1. Although I think that you should use the uniform_int_distribution function, providing you can take the advantage of C++11 standard. 


I believe that you should use OpenCV after all, instead of playing with new standards and some tricky functions. It contains the RNG class that you can easily use for generating of uniformly distributed sequence. Here is the example:

RNG rng;
float r_num = rng.uniform(0, 1);