Yankee Swap Number Generator

9

December 17, 2012 by Mike Hillwig

Like many companies, we have a lunch around this time of year where we exchange gifts. In my office, we do what’s called a Yankee Swap. This always means drawing numbers from a hat.

Somehow, this has become problematic in my office and nobody wants to be responsible managing the numbers. As I’ve said to many an intern in the past, “I can replace you with a SQL script.” And that’s just what I did here. Β Now, this is hardly an example of good code. I’m breaking the golden rule by putting a clustered index on a GUID. And worse yet, I’m sorting on a substring of a GUID. But I will submit that it’s still more random than pulling numbers from a hat, which allows people to cheat.

CREATE TABLE #ys_users

(PERSON VARCHAR(50),
ID UNIQUEIDENTIFIER PRIMARY KEY CLUSTERED NOT NULL DEFAULT NEWID())

INSERT #ys_users (PERSON) VALUES ('Tina')
INSERT #ys_users (PERSON) VALUES ('Chris')
INSERT #ys_users (PERSON) VALUES ('Jim')
INSERT #ys_users (PERSON) VALUES ('Mike')
INSERT #ys_users (PERSON) VALUES ('Cheryl')
INSERT #ys_users (PERSON) VALUES ('Tim')

SELECT PERSON FROM #ys_users ORDER BY LEFT(ID,1) ASC, LEFT(ID,2) DESC, LEFT(ID,3) ASC

DROP TABLE #ys_users

You can run this script over and over, and you will get a different result each time. Β The results will look something like this.

9 thoughts on “Yankee Swap Number Generator

  1. Brian K says:

    Or just sort by NEWID() and save the storage of six GUIDs.

  2. Mike Hillwig says:

    I never said it was good. I said it was random. πŸ™‚

  3. […] Yankee Swap Number GeneratorΒ – Using his initiative this weekΒ to put people out of work, it’s Mike Hilwig (Blog|Twitter). […]

  4. Suse, das stimmt, meistens kommen mehr neue Liebschaften hinzu, als man sich alter entledigt.Christina, Honig-Salz-Nüsse kânnten mir auch munden…Isi, freut mich.

  5. אנ×Âℒ לא Γƒβ€”Γ‚β„’Γƒβ€”Γ‚β€’Γƒβ€”Γ‚β€œΓƒβ€”Γ‚Β’ כמה מהכ×ÂΒͺΓƒβ€”Γ‚β€˜Γƒβ€”Γ‚β€ נכ×Â‒נה Γƒβ€”Γ‚β€ΊΓƒβ€”Γ‚β„’ Γƒβ€”Γ‚Ε“Γƒβ€”Γ‚β€ΊΓƒβ€”Γ‚β€’Γƒβ€”Γ‚ΒͺΓƒβ€”Γ‚β€˜Γƒβ€”Γ‚β„’Γƒβ€”Γ‚Β ×Âℒש Γƒβ€”Γ‚Β Γƒβ€”Γ‚ΛœΓƒβ€”Γ‚β„’Γƒβ€”Γ‚β„’Γƒβ€”Γ‚β€ להגז×Âℒם Γƒβ€”Γ‚ΒΓƒβ€”Γ‚β€˜Γƒβ€”Γ‚Ε“ ככה אנ×Âℒ Γƒβ€”Γ‚β€”Γƒβ€”Γ‚β€’Γƒβ€”Γ‚Β©Γƒβ€”Γ‚β€˜ שלא צר×Âℒ×Âő לגש×Â‒×ÂΒͺ Γƒβ€”Γ‚ΛœΓƒβ€”Γ‚Β’Γƒβ€”Γ‚β€’Γƒβ€”Γ‚β„’Γƒβ€”Γ‚β€’Γƒβ€”Γ‚Βͺ צר×Âℒ×Âő Γƒβ€”Γ‚Ε“Γƒβ€”Γ‚β€œΓƒβ€”Γ‚β€˜Γƒβ€”Γ‚Β¨ אם Γƒβ€”Γ‚β„’Γƒβ€”Γ‚Ε“Γƒβ€”Γ‚β€œΓƒβ€”Γ‚β„’Γƒβ€”Γ‚Β גל בקב מ×Â‒גן Γƒβ€”Γ‚β€ΊΓƒβ€”Γ‚β„’ ה×Â‒א ק×Â‒רה Γƒβ€”Γ‚β€ΊΓƒβ€”Γ‚Ε‘ א×Â‒ Γƒβ€”Γ‚β€ΊΓƒβ€”Γ‚Ε‘ Γƒβ€”Γ‚Βͺ׀ב×Âℒק×Â‒ לה×ÂΒͺכחש ה×Â‒ר×Âℒם .אל×Â‒ק×Âℒם × ×Â‒×ÂΒͺΓƒβ€”Γ‚ΕΈ ×Â‒ל×Â‒קח נראה לכם ב×ÂΒͺם Γƒβ€”Γ‚ΒΓƒβ€”Γ‚β€˜Γƒβ€”Γ‚Β‘Γƒβ€”Γ‚β€’Γƒβ€”Γ‚Β¨Γƒβ€”Γ‚β€œ שהאח×ÂΒͺ ה×Â‒לכ×ÂΒͺ לגש×Â‒×ÂΒͺ ה׀לה ×Â‒השנ×Âℒ×Âℒה Γƒβ€”Γ‚Ε“Γƒβ€”Γ‚ΛœΓƒβ€”Γ‚β„’Γƒβ€”Γ‚Β€Γƒβ€”Γ‚β€’Γƒβ€”Γ‚Ε“Γƒβ€”Γ‚β„’ ׀×Â‒ר×Âℒ×Â‒×ÂΒͺ זא×ÂΒͺ לא Γƒβ€”Γ‚β€Γƒβ€”Γ‚β€Γƒβ€”Γ‚β€”Γƒβ€”Γ‚Ε“Γƒβ€”Γ‚ΛœΓƒβ€”Γ‚β€ שלנ×Â‒ ה×Â‒א Γƒβ€”Γ‚Β§Γƒβ€”Γ‚β€’Γƒβ€”Γ‚β€˜Γƒβ€”Γ‚Β’ Γƒβ€”Γ‚ΒͺΓƒβ€”Γ‚Ε“Γƒβ€”Γ‚ΕΎΓƒβ€”Γ‚β€œΓƒβ€”Γ‚β€’ Γƒβ€”Γ‚Ε“Γƒβ€”Γ‚Β§Γƒβ€”Γ‚β€˜Γƒβ€”Γ‚Ε“ הכל Γƒβ€”Γ‚β€˜Γƒβ€”Γ‚ΒΓƒβ€”Γ‚β€Γƒβ€”Γ‚β€˜Γƒβ€”Γ‚β€

  6. @Icebergfinanza. Profumo e’ un banchiere di fiducia del pd, vogliono la patrimoniale per procurarsi un tesoretto onde avere un buon retratto per soddisfare le proprie clientele nazionali ed estere. Terza repubblica come la prima e seconda ma con molte piu’ tasse. Il pd finita l’urss, si e’ velocemente inteso con nuovi soggetti…esteri. Il problema (il nostro problema) e’ che il vecchio DAVA (rubli), il nuovo PRENDE (tanti euro).

  7. luis scrive:Concordo, ma non dimenticarti delle maul come le ha lasciate giocare ! Partita vinta con il cuore ma in quanto a gioco non ci siamo , soprattutto quando si attacca con i trequarti. Di bernardo -non da oggi- ha grande calcio, difende molto bene e quando serve va drittoperdritto, in questo momento molto meglio di Burton e ti dirò di più: più gioca e più migliora a mio avviso. Dietro manca l’imprevedibilità di Dingo, l’esperienza e la solidità di LaGrange e la forza di Loamanu.La fase difensiva invece la facciamo molto bene.

  8. http://www./ says:

    Keising, as a teen suffering with Gynecomastia, spent all of his free time trying to figure out how to get rid of man boobs without spending thousands of dollars on surgery or drugs. Now, several years later, he continues

  9. http://www./ says:

    Je n’ai pas dit que je préférais ΓƒΒͺtre ensablé, Ange. J’ai dit que j’avais un imaginaire du désert, du vent, des sables du désert. J’aime aussi les gouttes de mer mais dans d’autres circonstances… la mer que je porte en moi…

Leave a Reply

Your email address will not be published. Required fields are marked *