Operation on igraph_vector_t

I’m recently switching the code from Python to C++, and now I encounter some problems on igraph_vector_t.

  1. In Python, if I want to randomly choose an element from a list, I just have to import a random package and type in

Now I want to randomly pick a neighbor from the neighbor list of a vertex, so my code is

igraph_vector_int_t neis;
igraph_vector_int_init(neis, 0);
igraph_neighbors(&graph, neis, 0, IGRAPH_OUT);

How to randomly pick a neighbor from neis?

  1. After picking an element, I want to remove it from the igraph_vector_int_t. I want to do the same thing as in Python list.remove(element), what function should I call?

And, if I want to append a new element in the igraph_vector_int_t, what function should I call?

Thank you for answering me.

This question isn’t really related to igraph. In the future, please post such questions on general programming forums such as StackOverflow.

To select a random element of a vector, get the vector’s size n, then generate a random integer in the range [0, n).

igraph_integer_t n = igraph_vector_int_size(&neis);
igraph_integer_t k = RNG_INTEGER(0, n-1);
igraph_vector_int_remove(&neis, k);

For appending, use igraph_vector_int_push_back().