生成带日期的随机数

很简单的一个函数,就是根据当前的日期生成一个随机数。
程序代码 程序代码

<%
Function getRnd()
'****************************************
'返回值:如getRnd(),即输出200808241553464617,为2008年08月24日15时53分46秒4617随机数
'关联函数:formatInt()
'****************************************
getRnd = ""
getRnd = getRnd&formatInt(year(now),4)
getRnd = getRnd&formatInt(month(now),2)
getRnd = getRnd&formatInt(day(now),2)
getRnd = getRnd&formatInt(hour(now),2)
getRnd = getRnd&formatInt(minute(now),2)
getRnd = getRnd&formatInt(second(now),2)
randomize
ranNum=int((9000*rnd)+1000)
    getRnd = getRnd&ranNum
End Function

Function formatInt(Expression,Digit)
'****************************************
'函数名:formatInt
'作  用:输出Digit位左边带0整数
'参  数:Expression   ----要格式化整数
'参  数:Digit        ----要格式化位数
'返回值:如006,如FormatIntNumber(6,3),整数5被格式化为006
'关联函数:无
'****************************************
While Len(Expression) < Digit
  Expression = "0"&Expression
wend
formatInt = Expression
End Function

response.Write(getRnd()&"<br>")
response.Write(formatInt(24,5))'输出00024
%>



[本日志由 亮亮 于 2008-08-24 11:44 PM 编辑]
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: 随机数 日期
评论: 0 | 引用: 0 | 查看次数: -
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.