For a graph \(g\) with \(n\) nodes and \(m\) edges, the smallworldness \(S\) is defined as in Humphries and Gurney (2008):
\(S = (C_g / C_{rand}) / (L_g / L_{rand})\),
where \(C_g\) and \(C_{rand}\) are the clustering coefficient of \(g\) and that of a random graph with the same number of nodes and edges as \(g\), respectively. Also, \(L_g\) and \(L_{rand}\) are the mean shortest path length of \(g\) and that of the same random graph, respectively.
Here, in order to estimate \(C_{rand}\) and \(L_{rand}\), this function generates a large number of random graphs with \(n\) nodes and \(m\) edges under the Erdos-Renyi model (Erdos and Renyi, 1959), such that each edge is created with the same probability as the nodes in \(g\). This function then computes \(C\) and \(L\) for each random graph, and takes the average as the estimate for \(C_{rand}\) and \(L_{rand}\).