INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Usefull Functions & Procedures

How to create UNIQUE RANDOM Numbers ? by ramani
Posted: 4 Jun 01

You can cut & paste the following code and save the file as GenRand.Prg
*****************************************************
** FUNCTION NAME ... GenRand
** Author .......... Subramanian.G, FoxAcc
**        .......... ramani_g@yahoo.com
** Purpose ......... Generates required number of
**                   Unique random numbers (nHowMany)
**                   between the nLow & nHigh passed
** HowRun........... DO GenRand WITH nHigh,nLow,nHowMany
**       ... or..... =GenRand(nHigh,nLow,nHowMany)
** Limitations...... Size limited by Array
*****************************************************
** FUNCTION GenRand
PARAMETERS nLow, nHigh, nHowMany

** Exit the function if improperly called
IF PARAMETERS() < 3
   WAIT "PARAMETERS ERROR"
   RETURN .f.
ENDIF
IF nLow > nHigh OR nHowMany < 1 OR nHowMany > (nHigh-nLow)
   WAIT "PARAMETERS ERROR"
   RETURN .f.
ENDIF
**
PUBLIC nRandArray(nHowMany)
LOCAL nMyRand, nCount, nDuplicate
nCount = 1
nDuplicate = 0
DO WHILE nCount < nHowMany
    nMyRAND = INT(((nHigh-nLow+1)* RAND() ) + nLow)
    nDuplicate = ASCAN(nRandArray,nMyRand)
    IF nDuplicate # 0
       LOOP
    ENDIF
    nRandArray(nCount) = nMyRand
    nCount=nCount+1
ENDDO

RETURN .t.
**********************************************************
** Ramani  (Subramanian.G), FoxAcc, ramani_g@yahoo.com
** EOF
**********************************************************
Evaluate this to make others know how useful is this

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close