Random Graph Generation with igraph

  • Share this:

Code introduction


This function generates a random graph with a specified number of vertices and edges using the igraph library.


Technology Stack : igraph

Code Type : The type of code

Code Difficulty : Intermediate


                
                    
import igraph as ig
import random

def generate_random_graph(num_vertices, num_edges):
    """
    Generate a random graph with a given number of vertices and edges using igraph.
    """
    # Create a random graph with a specified number of vertices and edges
    g = ig.Graph.Random_Gnp_Serial(num_vertices, 2 * num_edges / num_vertices)
    
    return g

# JSON representation of the code                
              
Tags: