Changeset 2011 for TI02-CSML/trunk/csml


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

test added to check randomness or random id generator

File:
1 edited

Legend:

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

    r2010 r2011  
    44 
    55def getRandomID(): 
    6     #returns a random string that can be used as an internal identifier in a CSML document. 
     6    #returns a random 8 character alphanumeric string that can be used as an internal identifier in a CSML document. 
    77    #the ID only needs to be unique within the document that it occurs, so this is sufficiently random 
    88    #to make a clash extremely unlikely. The string is alphanumeric but always begins with a letter.   
     9    #Note: tested with 50000 ids and all were different 
    910    randomID=random.choice(string.letters) 
    1011    for i in range(7): 
     
    6465         
    6566def main(): 
    66     print getRandomID() 
     67    #test to check randomness of getRandomID() 
     68    idlist=[] 
     69    for j in range (500): 
     70        for i in range(100): 
     71            newid= getRandomID() 
     72            if newid in idlist: 
     73                print 'ID matched!!!'                
     74                sys.exit() 
     75            else:                 
     76                idlist.append(newid) 
     77        print i * j 
     78    print 'done' 
    6779     
    68 main() 
     80if __name__=="__main__": 
     81    main() 
Note: See TracChangeset for help on using the changeset viewer.