日期:2014-05-17 浏览次数:21057 次
'str---原字符串
'instr_str---需要随即插入的字符串,每个词请用都好隔开
'instr_len---插入的个数
function random_instr(str,instr_str,instr_len)
if trim(str)="" then '为空情况下的处理
random_instr=""
exit function
end if
if trim(instr_str)="" then '为空情况下的处理
random_instr=""
exit function
end if
if trim(instr_len)="" or not isnumeric(instr_len) then '为空情况下的处理
instr_len=1
end if
random_arr=split(instr_str,",")'分割需要随即插入的字符串
if UBound(random_arr)+1<instr_len then'当需要随即插入的字符串的个数小于设定的个数的时候,取需要随即插入的字符串的个数
instr_len=UBound(random_arr)+1
end if
eninser=""'保存已插入的字符串
for i=1 to instr_len
RANDOMIZE
random=round(len(str)*rnd())'随即插入的位置
inser_stred= eninser_str(instr_str,eninser)
if trim(eninser)="" then'保存已插入的字符串
eninser=inser_stred
else'保存已插入的字符串
eninser=eninser& "," &inser_stred
end if
stemp=left(str,random)
if random=0 then stempd=inser_stred & str else stempd= stemp&inser_stred end if 'random等于0时插入在第一个位置
str=replace(str,stemp,stempd)'顺序插入
next
random_instr=str
end function
function eninser_str(ByRef instrstrd,ByRef eninser)
random_arrs=split(instrstrd,",")'分割需要随即插入的字符
RANDOMIZE
randomd=round(UBound(random_arrs)*rnd())'随即取得要插入的字符串
strd=random_arrs(randomd)
if eninser="" then '为空情况下的处理
eninser_str=strd
exit function
end if
if instr(","& strd &",",","& eninser &",")>0 then'判断是否已插入数据
eninser_str instrstrd,eninser
else
eninser_str=strd
exit function
end if
end function
response.Write random_instr("2、3、4、5、6、7、8","A,F,D",2)