networks – interesting mathematical question related to the network

Write a command that generates a random network with n nodes that satisfy the
Requirements of the Erdos-Rényi model with probability p.
Write two procedures:
– Procedure one takes a given network, selects a node at random, determines its centrality of Katz
and add a link to the node with the next higher centrality, add a link from the node with
the next lower centrality;
– Procedure two takes a given network randomly selects a node, determines its Eigenvector
centrality and add a link to the node with the next highest centrality, add a link from the
node with the following lower centrality;

This is what I do, I'm stuck on how to select the node with the next higher and lower centrality.
enter the description of the image hereenter the description of the image here