Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Generating a random number
Message
De
01/09/2000 17:38:53
 
 
À
01/09/2000 17:03:47
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00411998
Message ID:
00412009
Vues:
15
>Does anyone know of a free/share ware program that will generate random numbers for patient ids? In the folloiwng format: 999-9999-99999. We are currently generating based of the patient's first, last name and date of birth but are experiencing some numbers being generated twice....

How 'bout the RAND() function?
Try this code for a test.
I tried it for 250000 records straight and didn't get the error message.
The WAIT WINDOW shows that it did retry - I only got 250 retries.
LOCAL ji, llError, lnErrCnt, lnRetry, lnRand
STORE 0 TO lnErrCnt, lnRetry, lnRand
CREATE TABLE testrand (crand c(14))
INDEX ON crand TAG crand CAND
SET ORDER TO
llError = .F.
ON ERROR llError = .T.
lnErrCnt =0
FOR ji = 1 TO 250000
  lnRand = RAND()*(10^12)
  IF MOD(ji,1000)#0
    ** every 1000 should fail
    m.crand = STRTRAN(TRANSFORM(lnRand,"999-9999-99999")," ","0")
  ENDIF
  INSERT INTO testrand FROM MEMVAR
  IF llError
    lnRetry=0
    DO WHILE llError AND lnRetry<=10 && only retry 10 times
      llError= .F.
      lnErrCnt = lnErrCnt+1
      WAIT WINDOW "Retries "+STR(lnErrCnt) NOWAIT
      lnRetry=lnRetry+1
      lnRand = RAND()*(10^12)
      m.crand = STRTRAN(TRANSFORM(lnRand,"999-9999-99999")," ","0")
      INSERT INTO testrand FROM MEMVAR
    ENDDO
    IF llError
      ** still have an error
      MESSAGEBOX("Could not generate unique number.")
      EXIT
    ENDIF
  ENDIF
ENDFOR
ON ERROR
Insanity: Doing the same thing over and over and expecting different results.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform