Vb6如何制作0-9的随机字符串和x字符的a-z [英] Vb6 How do I make a Random String of 0-9 and a-z of x characters

查看:83
本文介绍了Vb6如何制作0-9的随机字符串和x字符的a-z的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试创建一个随机字符串,使用0-9和a-z/A-Z长度x个字符,似乎找不到很好的例子,有什么主意吗?

Trying to create a random string, x characters in length using 0-9 and a-z/A-Z and can't seem to find a good example, any ideas?

推荐答案

Function RandomString(cb As Integer) As String

    Randomize
    Dim rgch As String
    rgch = "abcdefghijklmnopqrstuvwxyz"
    rgch = rgch & UCase(rgch) & "0123456789"

    Dim i As Long
    For i = 1 To cb
        RandomString = RandomString & Mid$(rgch, Int(Rnd() * Len(rgch) + 1), 1)
    Next

End Function

请注意,内置随机数生成器在密码学上不安全,因此不应使用此类函数来生成密码.

Please be aware that the built-in random number generator is not cryprographically secure so a function like this should not be used to generate passwords.

这篇关于Vb6如何制作0-9的随机字符串和x字符的a-z的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆