Forum OpenACS Q&A: Response to Coding: db vs tcl: Fastest Random Loop

Collapse
Posted by Jonathan Ellis on
You can make it a lot cleaner if you read your seven (6?) items into an array txt(0..$n_txt), then doing
proc_doc rotated_index { i n max } {
    returns index $i rotated $n places out of $max
} {
    return [expr ($i + $n) % $max]
}

set offset [ns_rand $n_txt]
for { set i 0 } { $i < $n_txt } { incr i } {
    append the_text $txt([rotated_index $i $offset $n_txt])
}