select one random element of a vector in c++

#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>

int main() {
    std::vector<int> myVector = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

    // Seed the random number generator
    std::srand(std::time(0));

    // Generate a random index within the range of the vector size
    int randomIndex = std::rand() % myVector.size();

    // Access the randomly selected element using the generated index
    int randomElement = myVector[randomIndex];

    // Display the randomly selected element
    std::cout << "Randomly selected element: " << randomElement << std::endl;

    return 0;
}