8个asp生成随机字符的函数
来源:asp之家 发布时间:2007-08-04 10:17:00
标签:随机函数,随机,随机字符,函数
呵呵,先说明一下下面的程序大部分收集自网络,因为本人在asp编程中经常使用到随机函数,所以收集了一些这类的函数,并做了些注释,方便使用。首发在asp之家。别看小小的随机字符串函数其实作用是很大的,就看你怎么发挥了。比如我们可以用他来在生成静态页面时的文件命名,应该很多的网站的都使用过。还有我们可以用它来生成随机密码等等。
function MyRandc(n)
’生成随机字符,n为字符的个数 ,该随机函数由大小写字母组成,不含数字
dim thechr
thechr = ""
for i=1 to n
dim zNum,zNum2
Randomize
zNum = cint(25*Rnd)
zNum2 = cint(10*Rnd)
if zNum2 mod 2 = 0 then
zNum = zNum + 97
else
zNum = zNum + 65
end if
thechr = thechr & chr(zNum)
next
MyRandc = thechr
end function
使用方法:
MyRandc(n) 生成随机字符,n为字符的个数,
如:
response.write MyRandn(10)
输出10个随机英文字母字符
2.
’功能说明:生成指定长度的随机字符,大小写英文字母加数字
function gen_key(digits)
’定义并初始化数组
dim char_array(80)
’初始化数字
for i = 0 to 9
char_array(i) = cstr(i)
next
’初始化大写字母
for i = 10 to 35
char_array(i) = chr(i + 55)
next
’初始化小写字母
for i = 36 to 61
char_array(i) = chr(i + 61)
next
randomize ’初始化随机数生成器。
do while len(output) < digits
num = char_array(int((61 - 0 + 1) * rnd + 0))
output = output + num
loop
’设置返回值
gen_key = output
end function
使用方法:
把结果返回给浏览器
response.write "本实例生成的十三位随机字符串为:"
response.write "<center>"
response.write gen_key(13) ‘这里可以更改长度
response.write "</center>"
0
投稿
猜你喜欢
- 详细参考:https://gitee.com/copperpeas/uniapp-paymentuniapp-payment介绍uniapp
- 一、简介你一定用过那种“OCR神器”,可以把图片中的文字提取出来,极大的提高工作效率。今天,我们就来做一款实时截图识别的小工具。顾名思义,运
- 匿名管道管道是一个单向通道,有点类似共享内存缓存.管道有两端,包括输入端和输出端.对于一个进程的而言,它只能看到管道一端,即要么是输入端要么
- 前言后续还会更新更多优雅的规范。命名风格1. 【强制】代码中的命名均不能以下划线或美元符号开始,也不能以下划线或美元符号结束。&n
- 一、tag简介tag是git版本库的一个标记,指向某个commit的指针。tag主要用于发布版本的管理,一个版本发布之后,我们可以为git打
- 这篇文章主要介绍了python如何使用socketserver模块实现并发聊天,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定
- 变量命名在《初识永远强大的函数》一文中,有一节专门讨论“取名字的学问”,就是有关变量名称的问题,本温故而知新的原则,这里要复习:名称格式:(
- 1、监听视频滑动给 swiper 增加 @change="change",这个时间在我们完成一次滑动后执行,在 meth
- 目的获得一个首尾不含多余空格的字符串方法 可以使用字符串的以下方法处理:string.lstrip(s[, chars])Return a
- 找了 很多 关于表格分页 点击事件 请求, table.render 并不支持监听点击事件,所以我就把 table.render 和 lay
- 本文实例为大家分享了python实现发送邮件功能的具体代码,供大家参考,具体内容如下# -*- coding: utf-8 -*- # Au
- Pytorch中torch.nn.Softmax的dim参数使用含义涉及到多维tensor时,对softmax的参数dim总是很迷,下面用一
- 关于__dict__和dir()的区别和作用请参考这篇文章:基于Python __dict__与dir()的区别详解说下我当时遇到的问题:c
- 用Python打开Excel数据,读取时需要将”学号“和“ID"转换成
- Linux Centos 下使用yum 命令安装mysql实现步骤1. 查看服务器中有没有安装过Mysql1. 查看有没有安装包: &nbs
- 不同类型的语言支持不同的数据类型,比如 Go 有 int32、int64、uint32、uint64 等不同的数据类型,这些类型占用的字节大
- 本文实例讲述了微信小程序实现图片上传、删除和预览功能的方法。分享给大家供大家参考,具体如下:这里主要介绍一下微信小程序的图片上传图片删除和图
- 本文实例讲述了python通过colorama模块在控制台输出彩色文字的方法。分享给大家供大家参考。具体分析如下:colorama是一个py
- 本文实例讲述了python在Windows8下获取本机ip地址的方法。分享给大家供大家参考。具体实现方法如下:import socket h
- 本文实例讲述了python根据路径导入模块的方法,分享给大家供大家参考。具体方法如下:常规做法如下:import sys sys.path.