Forum Discussion

Gary_105208's avatar
Gary_105208
Icon for Nimbostratus rankNimbostratus
Mar 20, 2009

How to Generate Visitor ID/UUID

We're trying to drop a unique visitor cookie that we control the persistence (i.e. 6 months age). I don't see anything in the iRule reference that close to helping.

 

 

Any recommendation on how to generate an unique identifier, or ideally UUID?

 

 

I see some UUID TCL libraries at http://tcllib.cvs.sourceforge.net/viewvc/tcllib/tcllib/modules/uuid/uuid.tcl?revision=1.9&view=markup but I don't believe these can be loaded into the F5?

 

 

Once I have that I can handle all the cookies, etc. I just need a unique id generator.

 

 

Thanks, Gary

12 Replies

  • To generate a random 9-digit number you can use the following:

     

     

    when HTTP_REQUEST {

     

    set client_id [format %09d [expr int(rand() * 1e9)]]

     

    }

     

     

    The exponents maximum is 9. Modify both the format-string and the exponent if required, please.

     

  • Thanks for the tip. That's a bit cleaner than the method we came up with in the linked post. You could wrap the expr arguments to save some conversions:

     

     

    % time {format %09d [expr int(rand() * 1e9)]} 1000

     

    21 microseconds per iteration

     

     

    % time {format %09d [expr {int(rand() * 1e9)}]} 1000

     

    6 microseconds per iteration

     

     

    Aaron