Last active
December 15, 2015 13:47
-
-
Save aloisdg/f50ef2c99a8f34b40cf7 to your computer and use it in GitHub Desktop.
A script to generate a secret santa. Target can be discover by qrcode.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net; | |
using System.Collections.Generic; | |
// https://dotnetfiddle.net/NC4suH | |
public class Program | |
{ | |
static readonly Random _rand = new Random(); | |
public static void Main() | |
{ | |
var list = new List<string> { "Pier","Noel", "Luke", "Leia", "Han " }; | |
var list2 = new List<string>(list); | |
cycle(list2); | |
for (var i = 0; i < list.Count; i++) | |
{ | |
Console.Write(list[i] + "\t"); | |
PrintData(GetDataAsBytes(CreateQrCodeUrl("Tu es le Secret Santa de " + list2[i]))); | |
} | |
} | |
public static void cycle<T>(IList<T> items) | |
{ | |
for (var i = items.Count; i > 1;) | |
{ | |
i--; | |
var j = (int) (_rand.NextDouble() * (i)); | |
var tmp = items[j]; | |
items[j] = items[i]; | |
items[i] = tmp; | |
} | |
} | |
public static string CreateQrCodeUrl(string text) | |
{ | |
return "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=" + text; | |
} | |
public static byte[] GetDataAsBytes(string url) | |
{ | |
return new WebClient().DownloadData(url); | |
} | |
public static void PrintData(byte[] image) | |
{ | |
Console.WriteLine("data:image/gif;base64," + Convert.ToBase64String(image)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment