The actual implementation of randomRange procedure isn't right. The last value of the range "never" result.
Example:
randomRange 4
random result [0, 2.5) ----> randomRange return 0 (25%)
[0.25, 0.5) --> 1 (25%)
[0.5, 0.75) --> 2 (25%)
[0.75, 1) ----> 3 (25%)
[1] ----------> 4 (0.00001%)
The last value of the range [0, 4] has only one option and the rest has 100/range percentage aprox.
I solve this problem by doing the following:
ad_proc -public randomRange {range} {
Returns a pseudo-random number between 0 and range.
@return integer
} {
incr range
return [expr [expr {int([random] * $range)}] % $range]
}