网络编程
位置:首页>> 网络编程>> Asp编程>> asp生成带日期的随机数

asp生成带日期的随机数

作者:亮亮 来源:亮亮blog 发布时间:2008-09-03 13:13:00 

标签:日期,随机,函数

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

<%
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
%>
0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com