Date: Fri, 9 Feb 2007 13:58:37 -0800 "Parise, Carol A." "SPSSX(r) Discussion" "Parise, Carol A." Re: random number with alpha text/plain; charset="iso-8859-1"

Hi all,

Both Gene and Richard's solution worked great.

I had generated random numbers in excel and imported them into SPSS. For Gene's solution to work...

I had to make sure my numbers were 6 digits or less.

These are both great little programs i am likely to use again.

Thanks

Carol

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]On Behalf Of Richard Ristow Sent: Friday, February 09, 2007 11:18 AM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Re: random number with alpha

At 12:27 AM 2/9/2007, Parise, Carol A. wrote:

>I'm creating what amounts to passwords and i want to do this with a 6 >digit random number + some character (either alpha or \$, & etc). > >Is SPSS able to create random characters? Also would someone know how >to put these 2 fields together?

To answer the latter question, the result has to be a character field. Use the STRING function to convert your number, then catenate.

To answer the first, you can get a random character by drawing a random integer in the appropriate range, and using it to look up in a list of characters.

In the following, the 6-digit random numbers are selected from the full range, 0 to 999999, and are entered into the password with leading 0's where necessary. The following is SPSS 15 draft output. (Code & output not saved separately.)

NEW FILE. INPUT PROGRAM. . NUMERIC LINE_NUM (F3). . String password(a7). . String #letters(a27). . Compute #letters='ABCDEFGHIJKLMNOPQRSTUVWXYZ\$'. . NUMERIC #Rand_Num (N6) /#Rand_Idx (F2). . STRING #Rand_Chr (A1). . LOOP LINE_NUM = 1 TO 5. . COMPUTE #Rand_Num = TRUNC(rv.uniform(0,1e6)). . COMPUTE #Rand_Idx = TRUNC(rv.uniform(1,28)). . COMPUTE #Rand_Chr = SUBSTR(#letters,#Rand_Idx,1). . Compute password = concat(STRING(#Rand_Num,N6), #Rand_Chr). . END CASE. . END LOOP. END FILE. END INPUT PROGRAM. LIST.

List |-----------------------------|---------------------------| |Output Created |09-FEB-2007 14:16:29 | |-----------------------------|---------------------------| LINE_NUM password

1 324996Q 2 472388M 3 747540O 4 148345X 5 890948G

Number of cases read: 5 Number of cases listed: 5

Back to: Top of message | Previous page | Main SPSSX-L page