locked
sys(3) file names RRS feed

  • Question

  • Does anyone know how the SYS(3) function generates its 8-digit values?  I understand that it's not guaranteed to come up with a unique value each time.  I just want to know a bit more of its internal workings.
    Thursday, June 24, 2010 4:38 PM

Answers

  • "seconds since midnight" are returned by SYS(2). SYS(3) also use them ?
    dni

    Yes exactly, sys(3) is seconds()*1000 in character form. sys(2015) is unique even if called within the same millisecond. ie:

     

    CREATE CURSOR uTest (s3 c(10), s2015 c(10))

    FOR ix = 1 TO 100

    INSERT INTO uTest VALUES (SYS(3),SYS(2015))

    ENDFOR

     

    SELECT COUNT(distinct s3) FROM uTest

    SELECT COUNT(distinct s2015) FROM uTest

    • Proposed as answer by dni Friday, June 25, 2010 12:03 PM
    • Marked as answer by Alex Liang Thursday, July 1, 2010 2:26 PM
    Friday, June 25, 2010 10:37 AM
  • You may check:

    http://msdn.microsoft.com/en-us/library/aa978575(v=VS.71).aspx and if is not enough then google (or bing) what is legal file name?...I think "internal workings" can be found only at ms.


    dni
    • Marked as answer by Alex Liang Thursday, July 1, 2010 2:25 PM
    Thursday, June 24, 2010 6:28 PM
  • It simply uses seconds since midnight. It is not reliable for uniqueness on today's machines. Instead use sys(2015).
    • Marked as answer by Alex Liang Thursday, July 1, 2010 2:25 PM
    Thursday, June 24, 2010 7:27 PM
  • SYS(3) uses miliseconds, it is visible at this short code:

    CLEAR
    FOR i = 1 TO 10 ? SECONDS() ? SYS(3) NEXT

    If you need unique value but not SYS(2015) then you may combine e.g. it with RAND():

    ? RIGHT(SYS(3), 4) + TRANSFORM(RAND()*10000, "@L 9999")

     

    • Marked as answer by Alex Liang Thursday, July 1, 2010 2:26 PM
    Thursday, June 24, 2010 9:22 PM

All replies

  • You may check:

    http://msdn.microsoft.com/en-us/library/aa978575(v=VS.71).aspx and if is not enough then google (or bing) what is legal file name?...I think "internal workings" can be found only at ms.


    dni
    • Marked as answer by Alex Liang Thursday, July 1, 2010 2:25 PM
    Thursday, June 24, 2010 6:28 PM
  • It simply uses seconds since midnight. It is not reliable for uniqueness on today's machines. Instead use sys(2015).
    • Marked as answer by Alex Liang Thursday, July 1, 2010 2:25 PM
    Thursday, June 24, 2010 7:27 PM
  • "seconds since midnight" are returned by SYS(2). SYS(3) also use them ?
    dni
    Thursday, June 24, 2010 8:09 PM
  • SYS(3) uses miliseconds, it is visible at this short code:

    CLEAR
    FOR i = 1 TO 10 ? SECONDS() ? SYS(3) NEXT

    If you need unique value but not SYS(2015) then you may combine e.g. it with RAND():

    ? RIGHT(SYS(3), 4) + TRANSFORM(RAND()*10000, "@L 9999")

     

    • Marked as answer by Alex Liang Thursday, July 1, 2010 2:26 PM
    Thursday, June 24, 2010 9:22 PM
  • "seconds since midnight" are returned by SYS(2). SYS(3) also use them ?
    dni

    Yes exactly, sys(3) is seconds()*1000 in character form. sys(2015) is unique even if called within the same millisecond. ie:

     

    CREATE CURSOR uTest (s3 c(10), s2015 c(10))

    FOR ix = 1 TO 100

    INSERT INTO uTest VALUES (SYS(3),SYS(2015))

    ENDFOR

     

    SELECT COUNT(distinct s3) FROM uTest

    SELECT COUNT(distinct s2015) FROM uTest

    • Proposed as answer by dni Friday, June 25, 2010 12:03 PM
    • Marked as answer by Alex Liang Thursday, July 1, 2010 2:26 PM
    Friday, June 25, 2010 10:37 AM
  • Thanks to you all - dni, Cetin and Pavel - for the information and advice.

    Geof

    Friday, June 25, 2010 12:12 PM