PDA

Click to See Complete Forum and Search --> : Really Random?


SteveCRM
Jan 17th, 2000, 08:15 AM
To randomize i use this:
Randomize
MyFile = int((6 + RND) + 1)

Does this produce a pattern? My friend says yes, I say no

Steve

chrisjk
Jan 17th, 2000, 09:11 AM
You are both right...the Randomize statement gets a seed value from the system time, and assuming you will not be running the code on the same second of every day, it produces a different set of numbers, so they are not completely random, but near enough.

Without the randomize statement, it would produce the same set of "random" numbers every time.

Regards

------------------
- Chris
chris.kilhams@btinternet.com
If it ain't broke - don't fix it :)


[This message has been edited by chrisjk (edited 01-17-2000).]

ivyl
Jan 17th, 2000, 05:32 PM
It's just like Chris writes. Randomize uses the system time to get a "random" number. You could however write the code like this to make it more clear:

Randomize Timer
MyFile = int((6 * RND) + 1)

BTW, if you type MyFile = int((6 + RND) + 1) then MyFile will always be 7 (maybe this was a typing error?)

Jan 17th, 2000, 07:10 PM
Guess he meant, int((6 + (RND * 10)) + 1)

------------------

Vincent van den Braken
EMail: azzmodan@azzmodan.demon.nl
ICQ: 15440110 (http://www.icq.com/15440110)
Homepage: http://www.azzmodan.demon.nl

Jan 17th, 2000, 08:24 PM
You could also create your own seed:
Dim Password As String
Dim Seed As Long
Dim x as Integer
Temp = Time
Seed = 0
If Mid(Temp, 2, 1) = ":" Then
Seed = Val(Mid(Temp, 1, 1)) + Val(Mid(Temp, 3, 1)) + Val(Mid(Temp, 4, 1)) + Val(Mid(Temp, 6, 1)) + Val(Mid(Temp, 7, 1))
Else
Seed = Val(Mid(Temp, 1, 1)) + Val(Mid(Temp, 2, 1)) + Val(Mid(Temp, 4, 1)) + Val(Mid(Temp, 5, 1)) + Val(Mid(Temp, 7, 1)) + Val(Mid(Temp, 8, 1))
End If


Then you could:
For x = 1 To Seed
'Your process here using the Rand function
Next x


I use this when generating truly random passwords. You can reseed anytime using the system time, and then just loop through the process the number of seed time using your random function in the loop.

------------------
Boothman
There is a war out there and it is about who controls the information, it's all about the information.



[This message has been edited by Boothman_7 (edited 01-18-2000).]