37 lines
891 B
Rust
37 lines
891 B
Rust
use noders::{
|
|
display::display,
|
|
graph::{Graph, NodeId},
|
|
};
|
|
use rand::{SeedableRng, prelude::*};
|
|
use rand_xorshift::XorShiftRng;
|
|
|
|
fn main() {
|
|
let mut rng = XorShiftRng::seed_from_u64(111111111112111122);
|
|
let mut graph = Graph::empty();
|
|
let root = graph.node("ROOT");
|
|
branch(&mut graph, &mut rng, root, vec![], 7, 5);
|
|
dbg!(graph.nodes.len());
|
|
display(graph);
|
|
}
|
|
|
|
pub fn branch(
|
|
graph: &mut Graph,
|
|
rng: &mut XorShiftRng,
|
|
parent: NodeId,
|
|
path: Vec<usize>,
|
|
max_children: usize,
|
|
max_depth: usize,
|
|
) {
|
|
if max_depth == 0 {
|
|
return;
|
|
}
|
|
let child_count = rng.random_range(0..max_children);
|
|
for index in 1..child_count {
|
|
let mut path = path.clone();
|
|
path.push(index);
|
|
let label = path.iter().map(ToString::to_string).collect::<Vec<_>>().join(".");
|
|
let child = graph.node(label);
|
|
graph.link(child, parent);
|
|
branch(graph, rng, child, path, max_children, max_depth - 1);
|
|
}
|
|
}
|