• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >ASP > ASP中一个用VBScript写的随机数类

ASP中一个用VBScript写的随机数类

作者: 字体:[增加 减小] 来源:互联网 时间:2017-05-11

通过本文主要向大家介绍了asp vbscript,asp vbscript教程,asp vbscript是什么,vbscript出入库软件,vbscript等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
外国人写的一个class,这么一点小小的应用,除非有特殊需求,还没有必要模块化。
用asp产生一个随机数。
<% 
''************************************************************************** 
'' CLASS: cRandom 
'' Calls randomize to seed the random number generator. 
'' Provides functions for returning ranged random integers or arrays of 
'' ranged random integers. 
'' Calling randomize to seed the random number generator at the time the 
'' class is created seemed like a reasonable thing to do. 
private sub Class_Initialize() 
'' Check the VBScript documentation for the specifics relating 
'' to the Randomize function 
Randomize 
end sub 
'' Terminate doesn''t need to do anything for this class 
private sub Class_Terminate() 
end sub 
''********************************************************************** 
'' FUNCTION: RangedRandom 
'' PARAMETER: lowerBound, the lowest allowable number to return 
'' PARAMETER: upperBound, the highest allowable number to return 
'' RETURNS: A random integer between lowerBound and UpperBound, 
'' inclusive 
''********************************************************************** 
public function RangedRandom( lowerBound, upperBound ) 
RangedRandom = CInt((upperBound - lowerBound) * Rnd + lowerBound) 
end function 
''********************************************************************** 
'' FUNCTION: RangedRandomArray 
'' PARAMETER: lowerBound, the lowest allowable number to return 
'' PARAMETER: upperBound, the highest allowable number to return 
'' PARAMETER: arraySize, zero based number specifying the size of the array 
'' PARAMETER: duplicates, true or false to indicate whether duplicate 
'' resize the tempArray to hold the number of elements passed in the 
'' arraySize parameter 
redim tempArray(arraySize) 
'' This is a loop counter, set it to 0 
filledElements = 0 
'' loop until filledElements is equal to the arraySize + 1 
do until filledElements = arraySize + 1 
'' Call the RangedRandom function with the lowerBound and upperBoundparameters 
tempValue = RangedRandom( lowerBound, upperBound ) 
'' Handle the case where we don''t want duplicate values 
if duplicates = false then 
badValue = false 
for i = 0 to UBound(tempArray) 
'' check if the new random value already exists in the array 
'' if it does set the badValue flag to true and break out of the loop 
if tempValue = tempArray(i) then 
badValue = true 
exit for 
end if 
next 
if badValue = false then 
tempArray(filledElements) = tempValue 
filledElements = filledElements + 1 
end if 
else 
'' Handle the case where duplicate values in the array are acceptable 
tempArray(filledElements) = tempValue 
filledElements = filledElements + 1 
end if 
loop 
'' return the array 
RangedRandomArray = tempArray 
end function 
end class 
%> 
<% 
'' All the code that follows is example code showing the use of the 
'' cRandom class. 
dim objRandom 
dim flip 
dim randomArray 
dim rowsToTest 
dim i, j 
'' create an instance of our class 
set objRandom = new cRandom 
'' set the number of iterations that we want to test 
rowsToTest = 10 
'' "toggle" to determine whether or not we set the bgcolor of the table row 
flip = true 
'' Start the table 
Response.Write "<table border=0 cellpadding=1 cellspacing=1>" 
for j = 0 to rowsToTest 
'' We''ll alternate the bgcolor of the table rows based on the 
'' value of the flip variable 
if flip then 
Response.Write "<tr bgcolor=LightGrey>" 
else 
Response.Write "<tr>" 
end if 
'' Call the RangedRandomArray function for testing purposes 
randomArray = objRandom.RangedRandomArray( 1, 10) </div>
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • ASP基础知识VBScript基本元素讲解
  • ASP(VBScript)中整除和取余
  • VBScript ASP CDbl() 函数转换为双精度类型
  • 推荐ASP中VBScript常用函数
  • ASP里面令人震撼地Debug类(VBScript)
  • asp,VBscript语法错误,史上最全最详细最精确第1/3页
  • javascript asp教程第四课 同时使用vbscript和javascript
  • ASP中一个用VBScript写的随机数类
  • ASP、vbscript编码模板

相关文章

  • 2017-05-11asp和php页面全面封杀WVS扫描器的代码
  • 2017-05-11使用FSO修改文件夹的名称实现文件转移防盗链
  • 2017-05-11ASP经典分页类
  • 2017-05-11ASP编码必备的8条原则
  • 2017-05-11很不错的一个UBB代码
  • 2017-05-11ASP中巧用Split()函数生成SQL查询语句的实例
  • 2017-05-11ASP,FSO遍历目录及目录下文件
  • 2017-05-11在Vista IIS 7 中用 vs2005 调试 Web 项目的注意事项
  • 2017-05-11雨哲浅谈关于防采集而不影响收录内容篇
  • 2017-05-11IE功能汇总

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 很不错的一个UBB代码
    • ASP生成静态文件编码为UTF-8格式的HTML文件
    • FSO操作文件系统
    • 如何使用ASP设置指定站点CPU最大使用程度
    • 一次性下载远程页面上的所有内容第1/2页
    • ASP基础入门第一篇(ASP技术简介)
    • 函数名称 函数功能
    • 无服务器做任意二级米子站
    • asp 得到动态数组中元素的个数
    • asp磁盘缓存技术使用的代码

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有