Does anyone know how to truly select random element from a vector v?
I tried this:
int rnd;
rnd = v[ (int)floor( (double)rand()*( (double)v.size() / (double)RAND_MAX ) ) ];
cout<< "Random element: "<<rnd;
But every time it's selecting only one particular element from my vector. It should be random right. I am not getting around this. You can suggest alternate code to display random element from a vector. But I just need single line function call to make efficient program. Don't want 3 or 4 line code for this.
Thanks,