Random 64 Characters alphanumeric String

  • Eirikur Eiriksson

    SSC Guru

    Points: 182369

    Jeff, have you been thinking about this for the last 7 years?

    ๐Ÿ˜Ž

  • Jeff Moden

    SSC Guru

    Points: 995164

    Eirikur Eiriksson (11/9/2016)


    Jeff, have you been thinking about this for the last 7 years?

    ๐Ÿ˜Ž

    Nah... just ran into the post. Just went through this in the company I work for, though. Base 26 and Base 36 numberings systems have more bad words than I do and I was in the U.S. Navy for more than 8 years. ๐Ÿ˜‰

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
    "If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
    "Change is inevitable... change for the better is not."
    When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. ๐Ÿ˜‰

    Helpful Links:
    How to post code problems
    Create a Tally Function (fnTally)

  • Mike Hinds

    SSCarpal Tunnel

    Points: 4248

    Really nice solution, Lynn!

    Mike Hinds Lead Database Administrator1st Source BankMCP, MCTS

  • ChrisM@Work

    SSC Guru

    Points: 186054

    Dunno how I landed here, but...here's how I'd do it in current versions (this doesn't work with '2005):

    SELECT CONVERT(CHAR(64),HASHBYTES('SHA2_512',CAST(NEWID() AS VARCHAR(36))),2)

    [font="Arial"]โ€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.โ€ - Gail Shaw[/font]


    For fast, accurate and documented assistance in answering your questions, please read this article[/url].
    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]
    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]
    [url

  • Eirikur Eiriksson

    SSC Guru

    Points: 182369

    For fun, a variation of Chris's solution
    ๐Ÿ˜Ž


    DECLARE @BINID VARBINARY(16) = NEWID();
    ;WITH BINARY_STUFF(DHASH,BINDATA,BINID)
    AS
    (
      SELECT CONVERT(CHAR(64),HASHBYTES('SHA2_512',CONVERT(VARCHAR(36),@BINID,0)),2),CONVERT(VARCHAR(36),@BINID,0),@BINID UNION ALL
      SELECT CONVERT(CHAR(64),HASHBYTES('SHA2_512',CONVERT(VARCHAR(36),@BINID,1)),2),CONVERT(VARCHAR(36),@BINID,1),@BINID UNION ALL
      SELECT CONVERT(CHAR(64),HASHBYTES('SHA2_512',CONVERT(VARCHAR(36),@BINID,2)),2),CONVERT(VARCHAR(36),@BINID,2),@BINID 
    )
    SELECT
      BS.DHASH
     ,BS.BINDATA
     ,BS.BINID
    FROM  BINARY_STUFF  BS;

    Sample output

    DHASH                                                            BINDATA                              BINID
    ---------------------------------------------------------------- ------------------------------------ ----------------------------------
    AF9BD5FDA0A507E82823FBFADEC8F9991C3E47E7FC927236653D1A3D9F3DC846 โ€ฐฦ’รŽรขโ€ฐzรEหœฦ’tห†dยถรผร                      0x8983CEE2897ADD459883748864B6FCCD
    8AF91B54BB28E29AA2E0EC9897CD93F20C6FF42BB249F0B34915085DF773516C 0x8983CEE2897ADD459883748864B6FCCD   0x8983CEE2897ADD459883748864B6FCCD
    25F9F7297DA8123DCFDB9A81D5AFCD0EF46217A4FA787D42E6AC32F744397BEE 8983CEE2897ADD459883748864B6FCCD     0x8983CEE2897ADD459883748864B6FCCD


Viewing 5 posts - 16 through 20 (of 20 total)

You must be logged in to reply to this topic. Login to reply