Generating a random password in Robotframework

I had need to also create a random password. Our systems allow pretty much all ASCII characters so thought I’d make something to generate these. This is why I have gone from Char 33 to 127 but you can adjust this to your taste.

Hope you find it useful.

generateRandomPassword
 [Arguments] ${passwordLength}=13
 @{validChars}= Create List StartValue
 :FOR ${i} IN RANGE 33 127
 \ ${evalStr}= Set Variable chr(${i})
 \ ${char}= Evaluate ${evalStr}
 \ Append To List ${validChars} ${char}
 ${temp}= Remove From List ${validChars} 0
${numberChars}= Get Length ${validChars}
 ${numberChars}= Run Keyword Evaluate ${numberChars}-1
 ${temp}= Set Variable random.randint(0, ${numberChars})
 
 ${randomPassword}= Set Variable \
 
 :FOR ${i} IN RANGE ${passwordLength}
 \ ${index}= Evaluate ${temp} modules=random,sys
 \ ${randChar}= Get From List ${validChars} ${index}
 \ ${randomPassword}= Catenate SEPARATOR= ${randomPassword} ${randChar}
 [Return] ${randomPassword}
Show your support

Clapping shows how much you appreciated Brad Bloomfield’s story.