Procedure.s mkpass(password_length)
chars$="abcdefghijklmnopqrstuvwxyz" ; possible characters, keep these lcase
For a=1 To password_length
Select Random(1) ; 0 = char, 1 = digit
Case 1 ; is digit
pass$+Str(Random(9))
Case 0 ; is character
position=Random(Len(chars$)) ; random character selector
char_case = Random(10)
If char_case<5 ; less than 5 is ucase
pass$+UCase(Mid(chars$,position,1))
Else
pass$+Mid(chars$,position,1)
EndIf
EndSelect
Next
ProcedureReturn pass$
EndProcedure
Debug mkpass(12)
I have used similar (my friend coded it to linux) to create automatic passwords which will be mailed to users after printed to paper (automatic user creation and password printing system)
Hmm, that's an OK procedure but you can neaten up a couple things: first, making a string of the alphabet and using Mid() to pick out letters isn't very neat, and second, doing a Random(10) and checking if it is less than 5 is a 50% chance, why not just use Random(1) and check if it is 0 or 1? Something like this (also if you have PB4.00+ you can make uppercases optional):
Procedure.s MakePass(Length.l, IncludeUpperCase = #False)
Define i.l, Result.s, Char.l
For i = 1 To Length
Char = Random(35)
If Char < 10
Result + Chr(Char + 48)
Else
If IncludeUpperCase And Random(1)
Result + Chr(Char + 55)
Else
Result + Chr(Char + 87)
EndIf
EndIf
Next i
ProcedureReturn Result
EndProcedure
Debug MakePass(12)
Debug MakePass(12, #True)