生成具有不同变量的随机输出
Generate random output with different variables
如何随机输出变量?我想随机排列输出变量
bind pub -|- !random proc:random
proc proc:random {nick host handle channel arg} {
set output1 "test1"
set output2 "test2"
set output3 "test3"
set output4 "test4"
set output5 "test5"
set output6 "test6"
set output7 "test7"
set ouput "$output1 $output2 $output3 $output4 $output5 $output6 $output7"
putnow "PRIVMSG $channel :$ouput"
}
输出应如下所示,例如:
第一次
set ouput "$output6 $output2 $output4 $output1 $output5 $output7 $output3"
第二次
set ouput "$output5 $output1 $output3 $output7 $output2 $output4 $output6"
第三次
set ouput "$output2 $output7 $output6 $output1 $output3 $output5 $output4"
要么你想要随机洗牌,要么你想要围绕一系列排列进行。前者更容易实现,因为您需要较少的持久状态,并且 Tcllib 已经为您提供了一个随机洗牌器。
# This is part of Tcllib
package require struct::list
bind pub -|- !random proc:random
proc proc:random {nick host handle channel arg} {
set randomItems {
"test1"
"test2"
"test3"
"test4"
"test5"
"test6"
"test7"
}
set output [struct::list shuffle $randomItems]
putnow "PRIVMSG $channel :$output"
}
还有很多其他方法可以生成要洗牌的列表。使用大文字非常非常容易...
(请注意,通常将 package require
调用外部过程放在脚本的顶部,以便在视觉扫描文件时很容易找到它们。Tcl 不强制执行此操作并且 永远不会强制执行它,但这绝对是个好风格。)
如何随机输出变量?我想随机排列输出变量
bind pub -|- !random proc:random
proc proc:random {nick host handle channel arg} {
set output1 "test1"
set output2 "test2"
set output3 "test3"
set output4 "test4"
set output5 "test5"
set output6 "test6"
set output7 "test7"
set ouput "$output1 $output2 $output3 $output4 $output5 $output6 $output7"
putnow "PRIVMSG $channel :$ouput"
}
输出应如下所示,例如:
第一次
set ouput "$output6 $output2 $output4 $output1 $output5 $output7 $output3"
第二次
set ouput "$output5 $output1 $output3 $output7 $output2 $output4 $output6"
第三次
set ouput "$output2 $output7 $output6 $output1 $output3 $output5 $output4"
要么你想要随机洗牌,要么你想要围绕一系列排列进行。前者更容易实现,因为您需要较少的持久状态,并且 Tcllib 已经为您提供了一个随机洗牌器。
# This is part of Tcllib
package require struct::list
bind pub -|- !random proc:random
proc proc:random {nick host handle channel arg} {
set randomItems {
"test1"
"test2"
"test3"
"test4"
"test5"
"test6"
"test7"
}
set output [struct::list shuffle $randomItems]
putnow "PRIVMSG $channel :$output"
}
还有很多其他方法可以生成要洗牌的列表。使用大文字非常非常容易...
(请注意,通常将 package require
调用外部过程放在脚本的顶部,以便在视觉扫描文件时很容易找到它们。Tcl 不强制执行此操作并且 永远不会强制执行它,但这绝对是个好风格。)