Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

random word generator
Hello,

I would like to generate random words consisting of
alphabets and numbers . the generated string is always of length 7

examples :

qwe3rff
kjadsgr
8jndlks

etc

a method i was thinking of was to create an array like this

arr[0]="a"
arr[1]="b"

Report this thread to moderator Post Follow-up to this message
Old Post
dada
03-20-04 01:24 AM


Re: random word generator
On 12 Mar 2004 15:59:29 -0800, usenetdada@yahoo.com (dada) wrote:

>Hello,
>
>I would like to generate random words consisting of
>alphabets and numbers . the generated string is always of length 7
>
>examples :
>
>qwe3rff
>kjadsgr
>8jndlks
>
>etc
>
>a method i was thinking of was to create an array like this
>
>arr[0]="a"
>arr[1]="b"
>   .
>   .
>   .
>arr[25]="z"
>arr[26]="0"
>arr[27]="1"
>   .
>   .
>arr[33]="9"
>
>and then concatenate the string(which is the random word and initially "") 
with
>arr[rand()]  where rand() picks a value betwwen 0 and 33
>the same thing would be done over 7 times
>but this seems to be a highly inefficeint way and also
>how to sprecify rand() like this
>generate random integers between 0 and 33  ?
>
>Can anybody suggest some method for this.
>thanks

I have found it worth while to write these sorts of things in general
ways.  This function is used to generate strings used for various
security purposes, including passwords. It takes the length of the
string as its only real argument.  You could fiddle with the character
range code to limit it to lower case, or just use it as is and run the
return through tolower().  The string is really only psuedorandom, of
course.

function RandomString( StringLength,   x, c, String ) {
# Returns a mixed case alphanumeric string containing StringLength
# number of characters.
srand()
# Generate an integer between 0 and 200, then discard any that are
# not in one of the desired ranges (48-57, 65-90, and 97-122).

for( x = 1; x <= StringLength; x++ ) {
while( 1 ) {
c = int( 200 * rand() )
if( c < 48 ) continue
if( ( c > 57 ) && ( c < 65 ) ) continue
if( ( c > 90 ) && ( c < 97 ) ) continue
if( c > 122 ) continue
break
}
String = String sprintf( "%c", c )
}
return( String )
}


T.E.D. (tdavis@gearbox.maem.umr.edu - e-mail must contain "T.E.D." or my .si
g in the body)

Report this thread to moderator Post Follow-up to this message
Old Post
Ted Davis
03-20-04 01:24 AM


Re: random word generator
I know it's an awk list, but... I had the same problem long ago, when I
had to generate several passwords. First i thought of using only awk,
but then I found an easier solution. Instead of trying to force awk to use
it's random and convert to chars, rather read bytes (or lines) from
/dev/urandom. It will contain everything from char 0 to char 255; just
drop what you don't need, count how many characters left and exit when you
have 7.

With awk, it's only one process; if you don't have awk for some reason,
with dd and sed (and/or tr) you can do the same: dd can count for you, sed
(and/or tr) can select what characters to keep. Backdraw of this method is
that you have to run more processes.

bye

Igor2

On Sat, 12 Mar 2004, dada wrote:

> Hello,
>
> I would like to generate random words consisting of
> alphabets and numbers . the generated string is always of length 7
>
> examples :
>
> qwe3rff
> kjadsgr
> 8jndlks
>
> etc
>
> a method i was thinking of was to create an array like this
>
> arr[0]="a"
> arr[1]="b"
>    .
>    .
>    .
> arr[25]="z"
> arr[26]="0"
> arr[27]="1"
>    .
>    .
> arr[33]="9"
>
> and then concatenate the string(which is the random word and initially "")
 with
> arr[rand()]  where rand() picks a value betwwen 0 and 33
> the same thing would be done over 7 times
> but this seems to be a highly inefficeint way and also
> how to sprecify rand() like this
> generate random integers between 0 and 33  ?
>
> Can anybody suggest some method for this.
> thanks
>

Report this thread to moderator Post Follow-up to this message
Old Post
Igor2
03-20-04 01:24 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 10:38 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.