Skip to content

Instantly share code, notes, and snippets.

@jdwaudby
Last active May 14, 2018 13:26
Show Gist options
  • Save jdwaudby/4131a23297bd608ed39f5b289d64a88e to your computer and use it in GitHub Desktop.
Save jdwaudby/4131a23297bd608ed39f5b289d64a88e to your computer and use it in GitHub Desktop.
LINQPad script for generating a randomised list of F1 drivers for any given total
int total = 18;
string[] drivers = {
"Sebastian Vettel, Ferrari",
"Kimi Räikkönen, Ferrari",
"Sergio Pérez, Force India-Mercedes",
"Esteban Ocon, Force India-Mercedes",
"Romain Grosjean, Haas-Ferrari",
"Kevin Magnussen, Haas-Ferrari",
"Stoffel Vandoorne, McLaren-Renault",
"Fernando Alonso, McLaren-Renault",
"Lewis Hamilton, Mercedes",
"Valtteri Bottas, Mercedes",
"Daniel Ricciardo, Red Bull Racing-TAG Heuer",
"Max Verstappen, Red Bull Racing-TAG Heuer",
"Nico Hülkenberg, Renault",
"Carlos Sainz Jr., Renault",
"Marcus Ericsson, Sauber-Ferrari",
"Charles Leclerc, Sauber-Ferrari",
"Pierre Gasly, Scuderia Toro Rosso-Honda",
"Brendon Hartley, Scuderia Toro Rosso-Honda",
"Lance Stroll, Williams-Mercedes",
"Sergey Sirotkin, Williams-Mercedes"
};
Random random = new Random();
int listsRequired = ((total - 1) / drivers.Length) + 1;
//listsRequired.Dump();
var driverList = new List<string>();
for (int i = 0; i < listsRequired; i++)
{
driverList.AddRange(drivers.OrderBy(x => random.Next()));
}
//driverList.GroupBy(x => x).Select(x => new {driver = x.Key, occurrence = x.Count()}).Dump();
// Final list
driverList.Take(total).Select((driver, i) => new { index = i + 1, driver}).Dump();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment