asp中实现随机分组程序的代码
程序员文章站
2023-11-12 15:07:58
复制代码 代码如下:function makegroup(teams() as string) as string&nbs...
复制代码 代码如下:
function makegroup(teams() as string) as string
'函数功能:对teams数组中的32支球队进行随机分组.(注:teams数组下标从0开始)
'函数的变量定义.
'显示变量声明是一个好习惯.
dim tvar as integer, returnstr as string, tmove as integer, temp as integer
'初始化随机数产生器实现真正的随机性.
randomize (timer)
for tvar = 1 to 32 '共有32支球队
if (tvar - 1) mod 4 = 0 then
'将分组球队名称及组名存入returnstr变量中.
returnstr = returnstr & vbcrlf & chr(asc("a") + (tvar \ 4)) & "组:"
end if
tmove = int(rnd * (33 - tvar))
returnstr = returnstr & teams(tmove) & "."
for temp = tmove to 30
'将数组的部分前移避免组中存在同名球队.
teams(temp) = teams(temp + 1)
next temp
next tvar
'返回值为分组后的结果.
makegroup = returnstr
end function