Ignore:
Timestamp:
17/01/07 08:46:53 (13 years ago)
Author:
domlowe
Message:

random ID generator for internal ids in a CSML document

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/csml/csmllibs/csmlextra.py

    r1899 r2010  
    11#Stuff with nowhere better to go 
     2import random 
     3import string 
    24 
     5def getRandomID(): 
     6    #returns a random string that can be used as an internal identifier in a CSML document. 
     7    #the ID only needs to be unique within the document that it occurs, so this is sufficiently random 
     8    #to make a clash extremely unlikely. The string is alphanumeric but always begins with a letter.   
     9    randomID=random.choice(string.letters) 
     10    for i in range(7): 
     11        randomID=randomID+random.choice(string.letters+string.digits) 
     12    return randomID 
     13     
    314 
    415def getSeqRule(nDims): 
     
    718        #This really needs more work to see if the +s and -s are correct. and the x/y/z s in right order 
    819        #nDims = spatial dimensions + time dimension 
     20         
     21        #TODO CSML2 - rewrite this 
    922        if nDims == 2: 
    1023                seq = "Linear" 
     
    1932         
    2033def getMappingRule(nDims): 
    21         #again, this needs a lot of work. 
     34        #TODO CSML2 - rewrite this 
    2235        if nDims == 2: 
    2336                mr = "+ gridI + series" 
     
    5063    return cleanstring 
    5164         
     65def main(): 
     66    print getRandomID() 
     67     
     68main() 
Note: See TracChangeset for help on using the changeset viewer.