1: ### 2: ## random [seed | value ] 3: ## 4: ## Generate a random number using only Tcl code. This proc tries to 5: ## emulate what the TclX random function does. If we don't have TclX 6: ## though, this is a decent substitute. 7: ### 8: 9: proc random {args} { 10: global _ran 11: 12: if {[llength $args] > 1} { 13: set _ran [lindex $args 1] 14: } else { 15: set period 233280 16: if {[info exists _ran]} { 17: set _ran [expr { ($_ran*9301 + 49297) % $period }] 18: } else { 19: set _ran [expr { [clock seconds] % $period } ] 20: } 21: return [expr { int($args*($_ran/double($period))) } ] 22: } 23: } |