Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
RAND()om my eyeballs!
Message
 
To
15/01/2002 16:11:09
Terrence Spencer
Municipal Advisory Council of Texas
Austin, Texas, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00605080
Message ID:
00605084
Views:
14
>Okay I thought I had this neat password generator setup and working fine...until I ran it again the next night and came up with the exact same "ramdom" passwords...in the exact same order as they were generated the night before. That is when I had to go to sleep.
>
>So I have a table of 1650 records with various unique names in it, and a field for the number of times the name has been used.
>Char(15), and numeric 1,0
>
>I pick a random number with RAND(). I go to the record number of the random number. So if rand() returned 147, I go to that record. I grab the name. Then I create another random number to add onto the beginning of the name so the suggested password might be 437texas, or 1263humbolt.
>
>In my application I am storing these passwords in a user account table, but mind you I am just testing. So I blow off 20 or 30 passwords, pleased with myself.
>
>The next night I come in again and generate a couple of passwords and I notice they are 'exactly' the same as last night and in the same order!
>
>Here is the code:
>
><snip>
>sele pwnames
>*I used 1.6 because I have 1620 records in my names table
> lnRandomRec = (RAND() * 1000 ) * 1.6
> GO lnRandomRec
> DO WHILE PWNames.Cnt > 5
> lnRandomRec = (RAND() * 1000 ) * 1.6
> GO lnRandomRec
> ENDDO
>
> REPLACE PWNames.Cnt WITH PWNames.Cnt + 1
> lcPassNumb = TRANSFORM((RAND() *1000),"999")
> lcPassName = TRIM(PWNames.Name)
> lcPassWord = lcPassNumb + lcPassName
><snip>
>
>I am sure there is a good explaination for this, or I am slipping over the edge.
>
Terrence,

The docs have a good explanation:

"RAND( ) returns the same sequence of random numbers if you use the same seed value for nSeedValue the first time you issue RAND( ) followed by subsequent RAND( ) function calls without nSeedValue.

If nSeedValue is negative the first time you issued RAND( ), a seed value from the system clock is used. To achieve the most random sequence of numbers, issue RAND( ) initially with a negative argument and then issue RAND( ) without an argument.

If you omit nSeedValue, RAND( ) uses a default seed value of 100,001."
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform