proc generate_random_dict {depth} {
set dict {}
set num_keys [expr {int(rand()*5) + 1}]
for {set i 0} {$i < $num_keys} {incr i} {
set key "key$i"
if {$depth > 0} {
# Value is another dict
set value [generate_random_dict [expr {$depth - 1}]]
} else {
# Value is a string
set value "value$i"
}
dict set dict $key $value
}
return $dict
}
# set dict [generate_random_dict 3]
递归真的太重要了