dbTalk Databases Forums  

Generating random string

comp.database.ms-access comp.database.ms-access


Discuss Generating random string in the comp.database.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
John
 
Posts: n/a

Default Generating random string - 04-15-2006 , 10:09 PM






Hi

I need to generate a string of six random characters to act as the first
password. Is there an example of how to do this somewhere?

Thanks

Regards



Reply With Quote
  #2  
Old   
Ira Solomon
 
Posts: n/a

Default Re: Generating random string - 04-16-2006 , 11:56 AM






This will do it:

Public Function MakePass()
Dim Lets(6) As String
Dim PW As String
Dim i, j, k As Integer
j = 1
Do While j < 6
k = Int((122 * Rnd) + 65)
If (k >= 65 And k < 91) Or (k > 96 And k < 123) Then
Lets(j) = Chr(k)
j = j + 1
End If
Loop
PW = Lets(1) & Lets(2) & Lets(3) & Lets(4) & Lets(5) & Lets(6)
MakePass = UCase(PW)
End Function

This generates the password in upper case. You can remove UCase to
get upper and lower. This will repeat letters sometimes. So you
might get : ABCDEB or CDXXSZ.

If dups are a problm let me know and I can add the code to avoid them.

Good luck
Ira Solomon

On Sun, 16 Apr 2006 04:09:00 +0100, "John" <John (AT) nospam (DOT) infovis.co.uk>
wrote:

Quote:
Hi

I need to generate a string of six random characters to act as the first
password. Is there an example of how to do this somewhere?

Thanks

Regards


Reply With Quote
  #3  
Old   
John
 
Posts: n/a

Default Re: Generating random string - 04-16-2006 , 02:28 PM



Thanks Ira. Works great.

Regards

"Ira Solomon" <isolomon (AT) solomonltd (DOT) com> wrote

Quote:
This will do it:

Public Function MakePass()
Dim Lets(6) As String
Dim PW As String
Dim i, j, k As Integer
j = 1
Do While j < 6
k = Int((122 * Rnd) + 65)
If (k >= 65 And k < 91) Or (k > 96 And k < 123) Then
Lets(j) = Chr(k)
j = j + 1
End If
Loop
PW = Lets(1) & Lets(2) & Lets(3) & Lets(4) & Lets(5) & Lets(6)
MakePass = UCase(PW)
End Function

This generates the password in upper case. You can remove UCase to
get upper and lower. This will repeat letters sometimes. So you
might get : ABCDEB or CDXXSZ.

If dups are a problm let me know and I can add the code to avoid them.

Good luck
Ira Solomon

On Sun, 16 Apr 2006 04:09:00 +0100, "John" <John (AT) nospam (DOT) infovis.co.uk
wrote:

Hi

I need to generate a string of six random characters to act as the first
password. Is there an example of how to do this somewhere?

Thanks

Regards




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.