I currently have a code like this:
g <- erdos.renyi.game(30, 151 , type = "gnm" , directed = F , loops = F)%>%
set_vertex_attr("a", value = 0)
V(g)$a <- sample(c(0, 1), vcount(g), replace = TRUE, prob = c(.25, .75))
g <- add_edges(g,c(sample(V(g)[V(g)$a==0],1), sample(V(g)[V(g)$a == 1], 1)))
I am trying to generate a random, new edge based on attribute values. However, currently due to the high density of edges in the graph, many times the generated edges are duplicates. How can I modify the last line of code so that it doesn't generate a duplicate edge?