注册 | 登陆

从一组数中取几个随机数

做了个简单的砸金蛋游戏,需要从50个金蛋中随机取5个金蛋供选择。

找了个函数,正合用。

ASP/Visual Basic代码
  1. <%   
  2. function showrnd(x,y)   
  3. if y<x then   
  4. exit function   
  5. end if   
  6. redim n(x)   
  7. dim i,q   
  8. dim isok   
  9. for i=1 to x   
  10. Randomize   
  11. n(i)=round((y-1)* Rnd)+1   
  12. isok=false   
  13. do while not isok   
  14. for q=1 to i   
  15. if n(i)=n(q-1) then   
  16. n(i)=Int((y-1)* Rnd)+1   
  17. isok=false   
  18. exit for   
  19. end if   
  20. isok=true   
  21. next   
  22. loop   
  23.     response.write n(i)"<br>"  
  24. next   
  25. end function   
  26.   
  27. '产生在1到50内的5个随机数   
  28. call showrnd(5,50)   
  29. %>  

Tags: asp, 随机数

« 上一篇 | 下一篇 »

只显示10条记录相关文章

ASP中获取SQL影响记录条数 (浏览: 584, 评论: 0)
asp 导入导出excel文档 (浏览: 2055, 评论: 0)
ASP脚本生成GUID的实现 (浏览: 1760, 评论: 0)
[转]WebServices启用HTTP GET和HTTP POST (浏览: 2014, 评论: 0)
较长数据无法在Asp页面中取出的三种解决方法 (浏览: 1695, 评论: 0)

Trackbacks

点击获得Trackback地址,Encode: UTF-8

发表评论

评论内容 (必填):