MIDRANGE dot COM Mailing List Archive



Home » RPG400-L » June 2008

RE: Random Character string generator???



fixed

Cool, thanks Chris!

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Chris Pando
Sent: Wednesday, June 18, 2008 12:26 PM
To: RPG programming on the AS400 / iSeries
Subject: Re: Random Character string generator???

On Wed, Jun 18, 2008 at 10:47 AM, Jon Allen <jallen@xxxxxxxxx> wrote:
I need to generate a random string of characters....

Best way to do this in RPGLE?

Thanks!


Best is a matter of opinion. Here is a 10 character
random password generator:

d randPwd pr 10a
d random pr ExtProc('CEERAN0')
d 10u 0
d 8f
d 12 Options(*Omit)
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* ... generate random password ... *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
p randPwd b
d pi 10a
d seed s 10u 0 Inz(0)
d floater s 8f
d fc s 12a
d pwd s 10a
d $I s 3s 0
d alpha s 26a Inz('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
/free
For $I = 1 to 10;
random( seed: floater : fc );
%SubSt( pwd : $I : 1 ) =
%SubSt( alpha : %Int(floater * 26 + 1) : 1 );
EndFor;
Return pwd;
/end-free
p randPwd e

A call looks like:

rndPwd = randPwd();


HTH,

Chris
--
chris@xxxxxxxxx
www.brilligware.com





Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2014 by MIDRANGE dot COM and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact