Index: openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl,v diff -u -r1.28.2.9 -r1.28.2.10 --- openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl 30 Sep 2019 19:06:05 -0000 1.28.2.9 +++ openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl 29 Nov 2019 11:12:34 -0000 1.28.2.10 @@ -896,8 +896,8 @@ set timezones [lc_list_all_timezones] set n [expr {[llength $timezones]-1}] - set desired_user_timezone [lindex $timezones [randomRange $n] 0] - set desired_system_timezone [lindex $timezones [randomRange $n] 0] + set desired_user_timezone [lindex $timezones [util::random_range $n] 0] + set desired_system_timezone [lindex $timezones [util::random_range $n] 0] set error_p 0 ad_try { Index: openacs-4/packages/acs-mail-lite/tcl/email-inbound-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-mail-lite/tcl/email-inbound-procs.tcl,v diff -u -r1.15.2.6 -r1.15.2.7 --- openacs-4/packages/acs-mail-lite/tcl/email-inbound-procs.tcl 20 Nov 2019 11:27:31 -0000 1.15.2.6 +++ openacs-4/packages/acs-mail-lite/tcl/email-inbound-procs.tcl 29 Nov 2019 11:12:34 -0000 1.15.2.7 @@ -1899,7 +1899,7 @@ # It will be 10 for a while.. # so use eleven 9's # Some cycles are saved by using a constant - append uid_partial "." [randomRange 99999999999] + append uid_partial "." [util::random_range 99999999999] append uid_partial "." [lindex $uid_list 2] set uid $uid_partial Index: openacs-4/packages/acs-mail-lite/tcl/test/email-inbound-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-mail-lite/tcl/test/email-inbound-procs.tcl,v diff -u -r1.7.2.4 -r1.7.2.5 --- openacs-4/packages/acs-mail-lite/tcl/test/email-inbound-procs.tcl 10 Aug 2019 14:45:54 -0000 1.7.2.4 +++ openacs-4/packages/acs-mail-lite/tcl/test/email-inbound-procs.tcl 29 Nov 2019 11:12:34 -0000 1.7.2.5 @@ -52,19 +52,19 @@ set param "-" append param $p if { $p in $bools_list } { - set val_idx [randomRange 5] + set val_idx [util::random_range 5] set val [lindex $bools_v_list $val_idx] } elseif { $p in $integer_list } { - set val [randomRange 32767] + set val [util::random_range 32767] } elseif { $p in $ints_list } { set nums_list [list] - set up_to_10 [randomRange 10] + set up_to_10 [util::random_range 10] for {set i 0} {$i < $up_to_10 } {incr i} { - lappend nums_list [randomRange 32767] + lappend nums_list [util::random_range 32767] } set val [join $nums_list " "] } elseif { $p in $lists_list } { - set val_idx [randomRange 2] + set val_idx [util::random_range 2] set val [lindex $nv_list_list $val_idx] } aa_log "r41. Testing change of parameter '${p}' from \ @@ -136,7 +136,7 @@ set lh_list [list l h] set subject [ad_generate_random_string] set su_glob "*" - append su_glob [string range $subject [randomRange 8] end] + append su_glob [string range $subject [util::random_range 8] end] # priority_types are in order of least significant first. set p_type_i 0 @@ -152,7 +152,7 @@ } # set new case of parameters - set r [randomRange 10000] + set r [util::random_range 10000] set p_min [expr { $r + 999 } ] set p_max [expr { $p_min * 1000 + $r } ] set su_max $p_max @@ -248,10 +248,10 @@ aa_log "r161 given: t0 '${t0}' dur_s '${dur_s}'" aa_log "r161b given: s0 '${s0}' su_max '${su_max}'" - set t1 [expr { int( $t0 - $dur_s * 1.9 * [random]) } ] - set t2 [expr { int( $t0 - $dur_s * 1.9 * [random]) } ] - set s1 [expr { int( $s0 * 0.9 * [random]) } ] - set s2 [expr { int( $s0 * 0.9 * [random]) } ] + set t1 [expr { int( $t0 - $dur_s * 1.9 * [util::random]) } ] + set t2 [expr { int( $t0 - $dur_s * 1.9 * [util::random]) } ] + set s1 [expr { int( $s0 * 0.9 * [util::random]) } ] + set s2 [expr { int( $s0 * 0.9 * [util::random]) } ] aa_log "r167 priorities: t1 '${t1}' t2 '${t2}' s1 '${s1}' s2 '${s2}'" if { $t1 < $t2 } { set t $t1 @@ -407,7 +407,7 @@ aa_log "Following three tests 'pass' when no imap sessions open." aa_false "ref367. acs_mail_lite::imap_conn_close -conn_id 'all'" $conn_id - set conn_id [randomRange 1000] + set conn_id [util::random_range 1000] if { [catch {set t3 [acs_mail_lite::imap_conn_close -conn_id $conn_id]} errmsg] } { set t3 1 } @@ -538,16 +538,16 @@ x-autorespond ] for {set ii 1} {$ii <= $i} {incr ii } { # send garbage to try to confuse proc - set t [randomRange 4] + set t [util::random_range 4] set h "" # Some examples already have header types that limit # test type. if { $type_arr(${ii}) eq "auto_gen" && $t > 2 } { - set t [randomRange 2] + set t [util::random_range 2] } if { $type_arr(${ii}) eq "in_reply_to" && $t > 1 } { - set t [randomRange 1] + set t [util::random_range 1] } set type_test [lindex $t_olist $t] @@ -565,16 +565,16 @@ } if { $t < 2 } { # add auto_reply headers - switch [randomRange 2] { + switch [util::random_range 2] { 0 { - append h [lindex $ar_list [randomRange 5]] + append h [lindex $ar_list [util::random_range 5]] append h " : " [ad_generate_random_string] } 1 { append h "action : delivered" } 2 { - set h2 [lindex $s_list [randomRange 3]] + set h2 [lindex $s_list [util::random_range 3]] append h "action : " $h2 "\n" append h "status : thisis a test" } @@ -583,22 +583,22 @@ } if { $t < 1 } { # add bounce headers - if { [randomRange 1] } { + if { [util::random_range 1] } { # test original-recipient (diverted, reply) append h "original-recipient : " append h [ad_system_owner] "\n" } else { # test delivery status notification append h action - append h " : " [lindex $s_list [randomRange 3]] + append h " : " [lindex $s_list [util::random_range 3]] append h "\n" status " : " - append h [expr { 99 + [randomRange 900] } ] " " - append h [ad_generate_random_string [randomRange 9]] + append h [expr { 99 + [util::random_range 900] } ] " " + append h [ad_generate_random_string [util::random_range 9]] append h "\n" } } # maybe mess up capitalization - set c [randomRange 3] + set c [util::random_range 3] switch -exact -- $c { 0 { set h [string tolower $h] @@ -650,14 +650,14 @@ $sect_id1 "" - set section [randomRange 100] + set section [util::random_range 100] set sect_id1 [acs_mail_lite::section_id_of $section] set sect_id2 [acs_mail_lite::section_id_of $section] aa_equals "r605 test case section '${section}'" \ $sect_id2 $sect_id1 set sect_arr(${sect_id1}) $section for {set i 0} {$i < 6} {incr i} { - append section "." [randomRange 100] + append section "." [util::random_range 100] set sect_id1 [acs_mail_lite::section_id_of $section] set sect_id2 [acs_mail_lite::section_id_of $section] aa_equals "r606 test case section '${section}'" \ @@ -701,13 +701,13 @@ set object_ct [llength $object_id_list] for {set i 0} {$i < 12} {incr i } { set package_id [lindex $package_id_list \ - [randomRange $package_ct]] + [util::random_range $package_ct]] set party_id [lindex $party_id_list \ - [randomRange $party_ct]] + [util::random_range $party_ct]] set object_id [lindex $object_id_list \ - [randomRange $object_ct]] + [util::random_range $object_ct]] set other [ad_generate_random_string] - set blank_id [randomRange 3] + set blank_id [util::random_range 3] set blank_field [lindex $fields_list $blank_id] set $blank_field "" # if package_id = aml_package_id, it still is signed here Index: openacs-4/packages/acs-tcl/tcl/utilities-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/utilities-init.tcl,v diff -u -r1.10 -r1.10.2.1 --- openacs-4/packages/acs-tcl/tcl/utilities-init.tcl 7 Aug 2017 23:48:00 -0000 1.10 +++ openacs-4/packages/acs-tcl/tcl/utilities-init.tcl 29 Nov 2019 11:12:34 -0000 1.10.2.1 @@ -8,7 +8,7 @@ } # initialize the random number generator -randomInit [ns_time] +util::random_init [ns_time] # Create mutex for util_background_exec nsv_set util_background_exec_mutex . [ns_mutex create oacs:bg_exec] Index: openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl,v diff -u -r1.189.2.37 -r1.189.2.38 --- openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl 22 Nov 2019 16:20:15 -0000 1.189.2.37 +++ openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl 29 Nov 2019 11:12:34 -0000 1.189.2.38 @@ -433,10 +433,16 @@ -ad_proc util_PrettyTclBoolean { +ad_proc -deprecated util_PrettyTclBoolean { zero_or_one } { Turns a 1 (or anything else that makes a Tcl IF happy) into Yes; anything else into No + + DEPRECATED: this proc is not localized, does not comply with + OpenACS naming convention and can be replaced by simple oneliner + idioms based e.g. on expr command + + @see plain tcl idioms involving message keys } { if {$zero_or_one} { return "Yes" @@ -445,30 +451,65 @@ } } -ad_proc -public randomInit {seed} { +ad_proc -deprecated randomInit {seed} { seed the random number generator. + + DEPRECATED: this proc does not respect OpenACS naming convention + + @see util::random_init } { + return [util::random_init $seed] +} + +ad_proc -public util::random_init {seed} { + Seed the random number generator. +} { nsv_set rand ia 9301 nsv_set rand ic 49297 nsv_set rand im 233280 nsv_set rand seed $seed } - -ad_proc -public random {} { +ad_proc -deprecated random {} { Return a pseudo-random number between 0 and 1. + + DEPRECATED: this proc does not respect OpenACS naming convention + + @see util::random } { + return [util::random] +} + +ad_proc -public util::random {} { + Return a pseudo-random number between 0 and 1. The reason to have + this proc is that seeding can be controlled by the user and the + generation is independent from tcl. + + @see util::random_init +} { nsv_set rand seed [expr {([nsv_get rand seed] * [nsv_get rand ia] + [nsv_get rand ic]) % [nsv_get rand im]}] return [expr {[nsv_get rand seed]/double([nsv_get rand im])}] } -ad_proc -public randomRange {range} { +ad_proc -deprecated randomRange {range} { Returns a pseudo-random number between 0 and range. + DEPRECATED: this proc does not respect OpenACS naming convention + + @see util::random_range + @return integer } { + return [util::random_range $range] +} + +ad_proc -public util::random_range {range} { + Returns a pseudo-random number between 0 and range. + + @return integer +} { incr range - return [expr {int([random] * $range) % $range}] + return [expr {int([util::random] * $range) % $range}] } ad_proc -public db_html_select_options { @@ -3430,7 +3471,7 @@ set len [llength $list] set result [list] while { [llength $list] > 0 } { - set index [randomRange [expr {[llength $list] - 1}]] + set index [util::random_range [expr {[llength $list] - 1}]] lappend result [lindex $list $index] set list [lreplace $list $index $index] } Index: openacs-4/packages/acs-tcl/tcl/test/acs-tcl-apm-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/test/acs-tcl-apm-procs.tcl,v diff -u -r1.10.2.3 -r1.10.2.4 --- openacs-4/packages/acs-tcl/tcl/test/acs-tcl-apm-procs.tcl 3 Sep 2019 06:35:55 -0000 1.10.2.3 +++ openacs-4/packages/acs-tcl/tcl/test/acs-tcl-apm-procs.tcl 29 Nov 2019 11:12:34 -0000 1.10.2.4 @@ -22,14 +22,14 @@ set package_list [db_list get_packages "select package_key from apm_package_types"] aa_log "List of packages: \{$package_list\}" - set list_index [randomRange [expr {[llength $package_list] - 1}]] + set list_index [util::random_range [expr {[llength $package_list] - 1}]] set package_key [lrange $package_list $list_index $list_index] set parameter_name [ad_generate_random_string] set description [ad_generate_random_string] set values { {number} {string} } - set index [randomRange 1] + set index [util::random_range 1] # # Choose randomly string or number parameter. Also choose @@ -64,7 +64,7 @@ set package_list [db_list get_packages "select package_key from apm_package_types"] aa_log "List of packages: \{$package_list\}" - set list_index [randomRange [expr {[llength $package_list] - 1}]] + set list_index [util::random_range [expr {[llength $package_list] - 1}]] set package_key [lrange $package_list $list_index $list_index] set instance_name "$package_key-[ad_generate_random_string]" Index: openacs-4/packages/acs-tcl/tcl/test/acs-tcl-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/test/acs-tcl-test-procs.tcl,v diff -u -r1.71.2.18 -r1.71.2.19 --- openacs-4/packages/acs-tcl/tcl/test/acs-tcl-test-procs.tcl 3 Sep 2019 06:35:55 -0000 1.71.2.18 +++ openacs-4/packages/acs-tcl/tcl/test/acs-tcl-test-procs.tcl 29 Nov 2019 11:12:34 -0000 1.71.2.19 @@ -765,7 +765,7 @@ -cats {api smoke} \ -procs { util::randomize_list - randomRange + util::random_range } \ util__randomize_list { Test util::randomize_list @@ -780,7 +780,7 @@ set randomized_list [util::randomize_list $org_list] aa_true "Ten-element list: $randomized_list" [util_sets_equal_p $org_list $randomized_list] - set len [randomRange 200] + set len [util::random_range 200] set org_list [list] for { set i 0 } { $i < $len } { incr i } { lappend org_list [ad_generate_random_string] Index: openacs-4/packages/acs-tcl/tcl/test/apm-parameter-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/test/apm-parameter-test-procs.tcl,v diff -u -r1.5.2.1 -r1.5.2.2 --- openacs-4/packages/acs-tcl/tcl/test/apm-parameter-test-procs.tcl 10 Mar 2019 21:34:33 -0000 1.5.2.1 +++ openacs-4/packages/acs-tcl/tcl/test/apm-parameter-test-procs.tcl 29 Nov 2019 11:12:34 -0000 1.5.2.2 @@ -81,7 +81,7 @@ }] { lassign $tuple parameter_name package_key default_value parameter_id - set value [random] + set value [util::random] if {$parameter_name ne "PasswordExpirationDays" && $value > 0.7} { set package_id [apm_package_id_from_key $package_key]