yog/generators/random
Stochastic graph generators for random graph models.
Values
pub fn barabasi_albert(n: Int, m: Int) -> model.Graph(Nil, Int)
Generates a scale-free network using the Barabási-Albert model.
Starts with m₀ nodes in a complete graph, then adds nodes using preferential attachment.
Time Complexity: O(nm)
Example
let graph = random.barabasi_albert(100, 3)
pub fn barabasi_albert_with_type(
n: Int,
m: Int,
graph_type: model.GraphType,
) -> model.Graph(Nil, Int)
Generates a Barabási-Albert graph with specified graph type.
pub fn erdos_renyi_gnm(n: Int, m: Int) -> model.Graph(Nil, Int)
Generates a random graph using the Erdős-Rényi G(n, m) model.
Exactly m edges are added uniformly at random.
Time Complexity: O(m) expected
Example
let graph = random.erdos_renyi_gnm(50, 100)
pub fn erdos_renyi_gnm_with_type(
n: Int,
m: Int,
graph_type: model.GraphType,
) -> model.Graph(Nil, Int)
Generates an Erdős-Rényi G(n, m) graph with specified graph type.
pub fn erdos_renyi_gnp(n: Int, p: Float) -> model.Graph(Nil, Int)
Generates a random graph using the Erdős-Rényi G(n, p) model.
Each possible edge is included independently with probability p.
Time Complexity: O(n²)
Example
let graph = random.erdos_renyi_gnp(50, 0.1)
pub fn erdos_renyi_gnp_with_type(
n: Int,
p: Float,
graph_type: model.GraphType,
) -> model.Graph(Nil, Int)
Generates an Erdős-Rényi G(n, p) graph with specified graph type.
pub fn random_tree(n: Int) -> model.Graph(Nil, Int)
Generates a uniformly random tree on n nodes.
Time Complexity: O(n²) expected
Example
let tree = random.random_tree(50)
pub fn random_tree_with_type(
n: Int,
graph_type: model.GraphType,
) -> model.Graph(Nil, Int)
Generates a random tree with specified graph type.
pub fn watts_strogatz(
n: Int,
k: Int,
p: Float,
) -> model.Graph(Nil, Int)
Generates a small-world network using the Watts-Strogatz model.
Creates a ring lattice where each node connects to k nearest neighbors, then rewires with probability p.
Time Complexity: O(nk)
Example
let graph = random.watts_strogatz(100, 4, 0.1)
pub fn watts_strogatz_with_type(
n: Int,
k: Int,
p: Float,
graph_type: model.GraphType,
) -> model.Graph(Nil, Int)
Generates a Watts-Strogatz graph with specified graph type.