Random Alpha-Numeric Code Generator Question?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

Random Alpha-Numeric Code Generator Question?

Post by Snickers » Tue Aug 14, 2007 1:49 pm

I am trying to create a 10 digit random password/id generator which will be used to create an access code for each user.

I am trying to use the following code to begin with but it doesn't seem to be working. I might possibly be testing it incorrectly as well.

is it possible to name variables using a variable in this method?

Code: Select all

Let>k=0

Label>StartLoop
//k will be part of the variable's name
Let>k=%k%+1
if>k<11>
  Random>61,var_%k%
  let>var_%k%=%var_%k%%+1
else
Let>ANCode=%var_1%%var_2%%var_3%%var_4%%var_5%%var_6%%var_7%%var_8%%var_9%%var_10%
MessageModal>%ANCode%
goto>End
endif

if>var_%k%=1
 let>var_%k%=a
endif

if>var_%k%=2
 let>var_%k%=b
endif

if>var_%k%=3
  let>var_%k%=c
endif

//...this pattern continues until after var_%k%= 26

if>var_%k%=26
  let>var_%k%=z
endif

//then it begins with the capital letters
if>var_%k%=27
  let>var_%k%=A
endif

if>var_%k%=28
  let>var_%k%=B
endif

if>var_%k%=29
  let>var_%k%=C
endif

//this pattern continues until number var_%k%=52
if>var_%k%=52
  let>var_%k%=Z
endif

//then it begins with the numbers
if>var_%k%=53
  let>var_%k%=0
endif

if>var_%k%=54
  let>var_%k%=1
endif

if>var_%k%=55
  let>var_%k%=2
endif

//this pattern continues until number var_%k%=62

if>var_%k%=62
  let>var_%k%=9
endif

goto>StartLoop

Label>End

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Aug 14, 2007 3:31 pm

Sorry to intrude. I have not taken the time to look at your code which is, I'm sure, what you would prefer. I wrote a similar program a couple of years ago. I might have already posted this but here it is. This writes the randomly generated text to a file of your choice and places the current text phrase on the clipboard for pasting into a form.

Code: Select all

Dialog>fin
  Caption=Complete
  Top=200
  Left=CENTER
  Width=300
  Height=100
  Label=Random word generator complete,55,20
EndDialog>fin

Dialog>paast
   Caption=Paste
   Width=191
   Height=150
   Top=CENTER
   Left=CENTER
   Label=Press CTRL+V to paste the word %CRLF%                %newword% %CRLF%       into your application.,10,20
   Button=Close,48,88,75,25,2
EndDialog>paast


Let>howmany=8
Let>wdlist=wordlist.csv
Deletefile>%TEMP_DIR%~alphalist~.tmp
Writeln>%TEMP_DIR%~alphalist~.tmp,result,1%CRLF%2%CRLF%3%CRLF%4%CRLF%5%CRLF%6%CRLF%7%CRLF%8%CRLF%9%CRLF%0%CRLF%a%CRLF%b%CRLF%c%CRLF%d%CRLF%e%CRLF%f%CRLF%g%CRLF%h%CRLF%i%CRLF%j%CRLF%k%CRLF%l%CRLF%m%CRLF%n%CRLF%o%CRLF%p%CRLF%q%CRLF%r%CRLF%s%CRLF%t%CRLF%u%CRLF%v%CRLF%w%CRLF%x%CRLF%y%CRLF%z%CRLF%
Writeln>%TEMP_DIR%deskpath~.bat,result,echo %homepath%> %TEMP_DIR%~homepath~
Let>RP_WINDOWMODE=0
Let>RP_WAIT=1
Run Program>%TEMP_DIR%deskpath~.bat
Readln>%TEMP_DIR%~homepath~,1,homep

Change Directory>%homep%\desktop
Input>Storefile,Name of file to store the generated words:%CRLF%(Pick Icon on the right to browse),wdlist
Let>kk=0
Label>repeat
Let>newword=
Input>howmany,How many characters in password.,howmany
If>howmany=quit,finish
If>howmany=,finish
Let>k=0
Label>makeword
Random>36,randchar
If>randchar=0,makeword
Label>makeword
Let>k=k+1
Readln>%TEMP_DIR%~alphalist~.tmp,randchar,randletter
concat>newword,randletter
If>k=howmany,end
goto>makeword
Label>end
Let>kk=kk+1
Writeln>Storefile,result,Word #%kk%      %newword%
Putclipboard>%newword%
//MessageModal>Press CTRL+V to paste the word %CRLF%%CRLF%                 %newword% %CRLF%%CRLF%        into your application.
Show>paast,result
Goto>repeat

Label>finish
Deletefile>%TEMP_DIR%~alphalist~.tmp
Writeln>Storefile,result,End of session******************
//MessageModal>Random word generator complete
Show>fin
Wait>2


Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

Post by Snickers » Tue Aug 14, 2007 3:39 pm

That is pretty much exactly what I am looking for; however, I want to do this without writing to a file. I was hoping to store the data in a variable.

Is it possible to name a variable using a variable?

Code: Select all

let>k=0

Label>StartLoop

Let>k=%k%+1
if>k<11>61,ran_gen
Let>var_%k%=ran_gen
else
Let>ANCode=%k%,%var_k%,%var_1%%var_2%%var_3%%var_4%%var_5%%var_6%%var_7%%var_8%%var_9%%var_10%
MessageModal>%ANCode%
goto>End
endif

Goto>StartLoop

Label>End
If I could create variables based on the variable %k%, I can assign a value to those variables based on the randomly generated number.

I don't know the format for creating variables based on another variable.

Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

Post by Snickers » Tue Aug 14, 2007 4:46 pm

This works; however I am going to need to add a bit more code to it so that their will be more number in it:

Code: Select all

Let>k=0

Label>StartLoop
//k will be part of the variable's name
Let>k=%k%+1
if>k<11>61,ran_gen
  Let>ran_gen=%ran_gen%+1
  Let>var_%k%=ran_gen
else
goto>End
endif
If>var_%k%=1
 let>var_%k%=1
 goto>StartLoop
endif
If>var_%k%=2
 let>var_%k%=2
 goto>StartLoop
endif
If>var_%k%=3
 let>var_%k%=3
 goto>StartLoop
endif
If>var_%k%=4
 let>var_%k%=4
 goto>StartLoop
endif
If>var_%k%=5
 let>var_%k%=5
 goto>StartLoop
endif
If>var_%k%=6
 let>var_%k%=6
 goto>StartLoop
endif
If>var_%k%=7
 let>var_%k%=7
 goto>StartLoop
endif
If>var_%k%=8
 let>var_%k%=8
 goto>StartLoop
endif
If>var_%k%=9
 let>var_%k%=9
 goto>StartLoop
endif
If>var_%k%=10
 let>var_%k%=10
 goto>StartLoop
endif
If>var_%k%=11
 let>var_%k%=a
 goto>StartLoop
endif
If>var_%k%=12
 let>var_%k%=b
 goto>StartLoop
endif
If>var_%k%=13
 let>var_%k%=c
 goto>StartLoop
endif
If>var_%k%=14
 let>var_%k%=d
 goto>StartLoop
endif
If>var_%k%=15
 let>var_%k%=e
 goto>StartLoop
endif
If>var_%k%=16
 let>var_%k%=f
 goto>StartLoop
endif
If>var_%k%=17
 let>var_%k%=g
 goto>StartLoop
endif
If>var_%k%=18
 let>var_%k%=h
 goto>StartLoop
endif
If>var_%k%=19
 let>var_%k%=i
 goto>StartLoop
endif
If>var_%k%=20
 let>var_%k%=j
 goto>StartLoop
endif
If>var_%k%=21
 let>var_%k%=k
 goto>StartLoop
endif
If>var_%k%=22
 let>var_%k%=l
 goto>StartLoop
endif
If>var_%k%=23
 let>var_%k%=m
 goto>StartLoop
endif
If>var_%k%=24
 let>var_%k%=n
 goto>StartLoop
endif
If>var_%k%=25
 let>var_%k%=o
 goto>StartLoop
endif
If>var_%k%=26
 let>var_%k%=p
 goto>StartLoop
endif
If>var_%k%=27
 let>var_%k%=q
 goto>StartLoop
endif
If>var_%k%=28
 let>var_%k%=r
 goto>StartLoop
endif
If>var_%k%=29
 let>var_%k%=s
 goto>StartLoop
endif
If>var_%k%=30
 let>var_%k%=t
 goto>StartLoop
endif
If>var_%k%=31
 let>var_%k%=u
 goto>StartLoop
endif
If>var_%k%=32
 let>var_%k%=v
 goto>StartLoop
endif
If>var_%k%=33
 let>var_%k%=w
 goto>StartLoop
endif
If>var_%k%=34
 let>var_%k%=x
 goto>StartLoop
endif
If>var_%k%=35
 let>var_%k%=y
 goto>StartLoop
endif
If>var_%k%=36
 let>var_%k%=z
 goto>StartLoop
endif

If>var_%k%=37
 let>var_%k%=A
 goto>StartLoop
endif
If>var_%k%=38
 let>var_%k%=B
 goto>StartLoop
endif
If>var_%k%=39
 let>var_%k%=C
 goto>StartLoop
endif
If>var_%k%=40
 let>var_%k%=D
 goto>StartLoop
endif
If>var_%k%=41
 let>var_%k%=E
 goto>StartLoop
endif
If>var_%k%=42
 let>var_%k%=F
 goto>StartLoop
endif
If>var_%k%=43
 let>var_%k%=G
 goto>StartLoop
endif
If>var_%k%=44
 let>var_%k%=H
 goto>StartLoop
endif
If>var_%k%=45
 let>var_%k%=I
 goto>StartLoop
endif
If>var_%k%=46
 let>var_%k%=J
 goto>StartLoop
endif
If>var_%k%=47
 let>var_%k%=K
 goto>StartLoop
endif
If>var_%k%=48
 let>var_%k%=L
 goto>StartLoop
endif
If>var_%k%=49
 let>var_%k%=M
 goto>StartLoop
endif
If>var_%k%=50
 let>var_%k%=N
 goto>StartLoop
endif
If>var_%k%=51
 let>var_%k%=O
 goto>StartLoop
endif
If>var_%k%=52
 let>var_%k%=P
 goto>StartLoop
endif
If>var_%k%=53
 let>var_%k%=Q
 goto>StartLoop
endif
If>var_%k%=54
 let>var_%k%=R
 goto>StartLoop
endif
If>var_%k%=55
 let>var_%k%=S
 goto>StartLoop
endif
If>var_%k%=56
 let>var_%k%=T
 goto>StartLoop
endif
If>var_%k%=57
 let>var_%k%=U
 goto>StartLoop
endif
If>var_%k%=58
 let>var_%k%=V
 goto>StartLoop
endif
If>var_%k%=59
 let>var_%k%=W
 goto>StartLoop
endif
If>var_%k%=60
 let>var_%k%=X
 goto>StartLoop
endif
If>var_%k%=61
 let>var_%k%=Y
 goto>StartLoop
endif
If>var_%k%=62
 let>var_%k%=Z
 goto>StartLoop
endif
goto>StartLoop

Label>End
Let>ANCode=%k%,%var_k%,%var_1%%var_2%%var_3%%var_4%%var_5%%var_6%%var_7%%var_8%%var_9%%var_10%
MessageModal>%ANCode%



[/code][/quote]

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Tue Aug 14, 2007 8:21 pm

Not very elegant, and I'm sure some vb guru will post a 2 line solution, but how about:

VBstart
VBend
Let>pass=
Let>n=0
Label>start
//generate a random number between 48 and 122
Random>74,mynum
Let>mynum=mynum+48
//Exclude ASCII codes for non alphanumeric characters
If>{(%mynum%>57)AND(%mynum%{(%mynum%>90)AND(%mynum%n=n+1
//convert the ASCII code to its character equivalent
VBEval>chr(%mynum%),mynum
//add the new character to the password
ConCat>pass,mynum
If>n=10,done
Goto>start
Label>done
MDL>pass

Note that this will use both upper and lower case alphas, and 0 to 9. If you only want upper case then you need to modify the code to include/exclude the correct ASCII code range.

Disclaimer: This is only as random as the macroscheduler random number generator, I am not making any claim as to the security of the resulting passwords.

Edit: Changed the VBEval

Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

Post by Snickers » Wed Aug 15, 2007 8:14 pm

Disclaimer: This is only as random as the macroscheduler random number generator
Is it possible to predict a number macro scheduler's random number generator may produce?

I finally created an alpha-numeric random number generator that produces outputs containing the following:

random length of password between 3-13 digits
28% chance of one character being a number 0-9
36% chance of one character being a lowercase letter
36% chance of one character being an uppercase letter

the user also puts his name into an input box where it is scrambled and mixed in with the other randomly generated digits

This seems pretty secure to me? no?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts