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,

did you seed the random-generator with srand() ?

Something like:

srand(time(NULL));
cout << rand()%v.size();

No. But my prof used the same stuff like
" srand(time(NULL)); "

What is this used for?
What is your first line of command? and what does second line do?

But you did exactly what my prof did. I donno though. Plz explain.

thanks,

Thanks dude. you know lot of stuff. I ll go thru your article. Thnx again.

This question has already been answered. Start a new discussion instead.