Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random alphanumeric combination... 1

Status
Not open for further replies.

Brezhnev

Programmer
Sep 25, 2002
53
CA
Hi all!
I need to generate random alphanumeric combination of 3.
For example : 3A4 .
Please note that it could happend that all three are digits or all three are letters. Playing around with
RAND() function but have a feeling there is a better way.

Need advise fast. Thanks a lot.
 
try right(sys2015(),3)

It may repeat itself, but the probability is very low that it would repeat itself very often. Of couse, there are only 36 cubed possibilities anyway, so at some point they will repeat.

You said you needed advise fast, so this is a fast answer.



Mike Krausnick
Dublin, California
 
Try this:
Code:
=Rand(-1)  &&... random seed from clock

CLEAR
FOR zzzz = 1 TO 20
   ?rand3()
NEXT 


*............. Rand3 ............
FUNCTION Rand3
Store '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' To cStr
STORE '' TO cRetStr

For zzz = 1 To 3
   nWhichItem = Int(36 * Rand() + 1)  &&.. 36 total possiblities
   cRetStr = cRetStr + Substr(cStr, nWhichItem, 1)  
Next
RETURN cRetStr

-Dave S.-
[cheers]
Even more Fox stuff at:
 
thanks a lot.Just one question -- why would i need first line ( = Rand(-1)) ?

thanks again
 
It is used to more or less initialize the 'randomizer'. From the help file:
If nSeedValue is negative the first time you issued RAND( ), a seed value from the system clock is used. To achieve the most random sequence of numbers, issue RAND( ) initially with a negative argument and then issue RAND( ) without an argument.




-Dave S.-
[cheers]
Even more Fox stuff at:
 
RAND(-1) seeds the random function with a clock value. This quasi-randomizes the random number generator. If you did not first seed the function and then produced two lists of random numbers, those two lists would be identical. If you then seed the function, the two lists of random numbers will be different.
 
question is closed ..thanks a lot guys for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top