密码生成器 [英] Password Generator

查看:146
本文介绍了密码生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了密码生成器

Hi I made password generator

Public Function RndWord(ByVal WordLength As Integer) As String
       Dim TempWord As String
       Dim loopvar As Integer
       For loopvar = 1 To WordLength
           TempWord = TempWord & Mid("abcdefgABCDEFG", Int(Rnd() * 14) + 1, 1)
       Next loopvar
       RndWord = TempWord
   End Function



每次我第一次使用时,每次都会生成相同的前三个密码!



and every time I use first use it generates the same first 3 passwords every time! how can I fix this???

推荐答案

在使用Rnd()之前,请先使用Randomize().


在VB中,Rnd()使用数学方程式生成下一个随机"数.

但是,由于已知实际操作,因此您可以预测下一个值.

但是,给定一个arbitray起始值,这些数字具有良好的分布-这些是伪随机"数字.

为了避免Rnd()从相同的数字开始(并因此每次给出相同的数字序列),应调用Randomize()以使用计算机时钟设置初始值(称为种子).

可以的话,请在.Net中使用System.Random.
Before using Rnd(), use Randomize().


In VB, Rnd() uses a maths equation to produce the next ''random'' number.

But, because the actual operation is known you can predict the next value.

However given an arbitray start value the numbers have good distribution - these are ''pseudo-random'' numbers.

To keep Rnd() from startng at the same number (and hence giving the same sequence of numbers every time), Randomize() should be called to use the machine clock to set the initial value (called a seed).

In the .Net use System.Random instead if you can.


有关文档的内容[
What about documentation [^]:

对于任何给定的初始种子,由于每个对Rnd函数的后续调用都使用前一个数字作为参数,因此生成了相同的数字序列.该序列中下一个数字的种子.
在调用Rnd之前,使用不带参数的Randomize语句使用基于系统计时器的种子初始化随机数生成器.
For any given initial seed, the same number sequence is generated because each successive call to the Rnd function uses the previous number as a seed for the next number in the sequence.
Before calling Rnd, use the Randomize statement without an argument to initialize the random-number generator with a seed based on the system timer.



?



?


为什么要在.NET类中调用Rnd()?为什么不使用.NET方法?我不知道Rnd()是如何播种的,但是您的问题是种子是相同的. PC上没有诸如随机数之类的东西.
Why are you calling Rnd() in a .NET class ? Why not use the .NET methods ? I have no idea how Rnd() is seeded, but your issue is that the seed is the same. There''s no such thing as random numbers on a PC.


这篇关于密码生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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