Advertisement
miljdze

Untitled

Jun 5th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Threading;
  7.  
  8. namespace RandomizacijaKarta
  9. {
  10. class Program
  11. {
  12. public static Random r = new Random();
  13.  
  14. public static void ImaNema()
  15. {
  16. int ima = r.Next(0, 2);
  17. if (ima == 1)
  18. {
  19. Console.WriteLine("{0} ima kartu", Thread.CurrentThread.Name);
  20. }
  21. else
  22. {
  23. Console.WriteLine("{0} nema kartu", Thread.CurrentThread.Name);
  24.  
  25. }
  26.  
  27. }
  28. static void Main(string[] args)
  29. {
  30. Thread[] threads = new Thread[10];
  31.  
  32. for(int i = 0; i < threads.Length; i++)
  33. {
  34. threads[i] = new Thread(ImaNema);
  35. threads[i].Name = string.Format("Putnik #{0}", i+1);
  36. threads[i].Start();
  37. }
  38. for (int i = 0; i < threads.Length; i++)
  39. {
  40. threads[i].Join();
  41. }
  42.  
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement