Build random generated data.
24-DEC-1999 Created routine
12-NOV-2000 Modified to use byte arrays and changed the logic flow. Added
a new switch for the amount to data to be returned if it is
converted to Hex format.
01-APR-2001 Thanks to Plex <PlexusR@netscape.net> for pointing me in the
right direction.
1. Redimmed the byte array (bad) instead of the string array prior
to returning the values when creating ASCII printable characters.
See routine Build_Random_Data.
2. Added -1 to UBound size to take into account the zero based array.
This was producing null values in the byte array.
Use this CLASS module as a guideline. Your imagination is your
only limitation.
---------------------------------------------------
From Microsoft's MSDN:
Randomize uses a number to initialize the Rnd function's
random-number generator, giving it a new seed value. If
you omit number, the value returned by the system timer
is used as the new seed value.
If Randomize is not used, the Rnd function (with no
arguments) uses the same number as a seed the first time
it is called, and thereafter uses the last generated
number as a seed value.
Note: To repeat sequences of random numbers, call Rnd
with a negative argument immediately before using
Randomize with a numeric argument.
Using Randomize with the same positive value does not
repeat the previous sequence.
---------------------------------------------------
Example for repeatable values:
Dim i As Integer
Dim k As Integer
' the values never change
Do
Rnd -1 ' perform a reset
Randomize 999 ' start with any fixed value
For i = 1 To 10
k = Int(Rnd * 6) ' like rolling loaded dice
Debug.Print Format(Format(k, "##"), "@@ ");
Next
Debug.Print ' look in Debug immediate window
Stop ' Press F5 to do another loop
Loop
---------------------------------------------------
When you use Randomize by itself, the default is to use the
TIMER. TIMER is the system date and time returned as a
single precision number unique at that particular time.
This is a very good starting point for most of us; however,
it is a predictable value. All one has to do is look at
the time stamp of the encrypted data and calculate the
starting point of the random generation.
You should always use a truely unique value for seeding
the random number generator prior to generating any new
values.
There are three routines that I use to create a seed value for
the random number generator. These are randomly picked whenever
I call the Build_Random_Data routine.
I have updated this class to use byte arrays, removed obsolete
variables, and modified several of the routines.
Be sure to read all the documentation within the modules.
-----------------------------------------------------------------
Written by Kenneth Ives kenaso@home.com
All of my routines have been compiled with VB6 Service Pack 4.
There are several locations on the web to obtain these
modules.
Whenever I use someone else's code, I will give them credit.
This is my way of saying thank you for your efforts. I would
appreciate the same consideration.
Read all of the documentation within this program. It is very
informative. Also, if you learn to document properly now, you
will not be scratching your head next year trying to figure out
exactly what you were programming today. Been there, done that.
This software is FREEWARE. You may use it as you see fit for
your own projects but you may not re-sell the original or the
source code. If you redistribute it you must include this
disclaimer and all original copyright notices.
No warranty express or implied, is given as to the use of this
program. Use at your own risk.
If you have any suggestions or questions, I'd be happy to
hear from you.
-----------------------------------------------------------------
You should always use a truely unique value for seeding the
需积分: 50 47 浏览量
2006-02-23
09:05:59
上传
评论
收藏 10KB ZIP 举报
评论0
最新资源