vendredi 8 mai 2015

Generate random number within specified range without REDUNDANCY in TCL

hi I need to generate 30 random numbers without any repeatations of numbers in TCL.

Here is the code to generate random number which works fine, but will generate redundant numbers.

proc myRand { min max } {
   set maxFactor [expr [expr $max + 1] - $min]
   set value [expr int([expr rand() * 100])]
   set value [expr [expr $value % $maxFactor] + $min]
return $value
}

for {set i 1} {$i < 31} {incr i} {
upvar 0 fnode($i) fnod($i)
set fnod($i) [myRand 1 20] ;# random number is generated between 1 to 20 
}

Anyone please help out.




Aucun commentaire:

Enregistrer un commentaire