fork(4) download
  1. using System;
  2.  
  3. public class Sorteio
  4. {
  5. static Random _random = new Random();
  6.  
  7. public static void Shuffle<T>(T[] array)
  8. {
  9. var random = _random;
  10. for (int i = array.Length; i > 1; i--)
  11. {
  12. int j = random.Next(i);
  13. T tmp = array[j];
  14. array[j] = array[i - 1];
  15. array[i - 1] = tmp;
  16. }
  17. }
  18.  
  19. public static void Main()
  20. {
  21. string[] array = {
  22. "José",
  23. "Carlos",
  24. "João",
  25. "Miriam",
  26. "Estela"
  27. };
  28. Shuffle(array);
  29. foreach (string value in array)
  30. {
  31. Console.WriteLine(value);
  32. }
  33. }
  34. }
Success #stdin #stdout 0.02s 34816KB
stdin
Standard input is empty
stdout
Miriam
Carlos
João
José
Estela