找回密码
 注-册

QQ登录

只需一步,快速开始

查看: 1496|回复: 0

[ASP] ASP 从1-50中随机选择8个数,不能重复的例子

[复制链接]
Leya 发表于 2008-3-31 10:57:05 | 显示全部楼层 |阅读模式
Randomize 是随机初始化,使用rnd之前必须要先来一句Randomize

rnd-随机函数,用于随机,为了防止重复,你可以用一个数组(如果是用来随机整数,开Bool数组,随机实数九要开实数数组)来保存已经随机出来的结果,每随机一个判断一下是否随机过,具体实现方法,要看你的数据类型了,
  1. <%
  2. session("jl")=""
  3. a1=setnum()
  4. a2=setnum()
  5. a3=setnum()
  6. a4=setnum()
  7. a5=setnum()
  8. a6=setnum()
  9. a7=setnum()
  10. a8=setnum()

  11. response.Write(a1 & "
  12. ")
  13. response.Write(a2 & "
  14. ")
  15. response.Write(a3 & "
  16. ")
  17. response.Write(a4 & "
  18. ")
  19. response.Write(a5 & "
  20. ")
  21. response.Write(a6 & "
  22. ")
  23. response.Write(a7 & "
  24. ")
  25. response.Write(a8 & "
  26. ")

  27. function setnum()
  28. Randomize
  29. jlsz=split(session("jl"),";")
  30. cfbj=2
  31. while cfbj=2
  32. setnum=int(rnd()*50)
  33. for i=0 to Ubound(jlsz)-1
  34. cf=0
  35. if cint(setnum)=cint(jlsz(i)) then
  36. cf=1
  37. exit for
  38. end if
  39. next
  40. if cf=0 then
  41. cfbj=0
  42. else
  43. cfbj=2
  44. end if
  45. wend
  46. session("jl")=session("jl")& setnum &";"
  47. end function
  48. %>
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注-册

本版积分规则

Archiver|手机版|小黑屋|DoDVip ( 桂ICP备14000730号 )

GMT+8, 2025-5-1 17:49 , Processed in 0.059448 second(s), 21 queries .

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表