Advertisement
Guest User

generator

a guest
Jul 31st, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.40 KB | None | 0 0
  1. const int count = 10000,
  2.     interval = 50,
  3.     max = 200;
  4. string[] str =
  5. {
  6.     "Заявка прошла ", "Заявка отклонена ", "Ставка повышена ", "Ставка понижена ",
  7.     "Индекс понижен ", "Индекс повышен ", "Неизвестная ошибка ", "Заблокировано "
  8. };
  9. var rnd = new Random();
  10. var timer = new System.Timers.Timer() {Interval = interval, Enabled = true};
  11. int l = str.Length;
  12. var output = new StringBuilder();
  13. int i = 0, current = 0;
  14. timer.Elapsed += (sender, e) =>
  15. {
  16.     Console.WriteLine(output);
  17.     current = 0;
  18.     output.Clear();
  19. };
  20. while (i < count)
  21. {
  22.     if (current < max)
  23.     {
  24.         output.Append(str[rnd.Next(l)]);
  25.         output.Append('\n');
  26.         i++;
  27.         current++;
  28.     }
  29. }
  30. timer.Dispose();
  31. Console.ReadKey();
  32.  
  33.  
  34. (создаем таймер, который каждые 50 миллисекунд выполняет этот кусок кода:
  35. Код C#
  36.  
  37. {
  38.     if (i++ == count)
  39.         (sender as IDisposable).Dispose();
  40.     else
  41.         Console.WriteLine(str[rnd.Next(str.Length)]);
  42. };)
  43. int count = 200,
  44.     interval = 20;
  45. string[] str =
  46. {
  47.     "Заявка прошла ", "Заявка отклонена ", "Ставка повышена ", "Ставка понижена ",
  48.     "Индекс понижен ", "Индекс повышен ", "Неизвестная ошибка ", "Заблокировано "
  49. };
  50. var rnd = new Random();
  51. var timer = new Timer(interval);
  52. int i = 0;
  53. timer.Elapsed += (sender, e) =>
  54. {
  55.     if (i++ == count)
  56.         (sender as IDisposable).Dispose();
  57.     else
  58.         Console.WriteLine(str[rnd.Next(str.Length)]);
  59. };
  60. timer.Enabled = true;
  61. Console.ReadLine();
  62. Во втором случае выводим 200 сообщений, приостанавливая работу программы после каждого на 20 мс
  63. int count = 200,
  64.     interval = 20;
  65. string[] str =
  66. {
  67.     "Заявка прошла ", "Заявка отклонена ", "Ставка повышена ", "Ставка понижена ",
  68.     "Индекс понижен ", "Индекс повышен ", "Неизвестная ошибка ", "Заблокировано "
  69. };
  70. var rnd = new Random();
  71. for (int i = 0; i < count; i++)
  72. {
  73.     Console.WriteLine(str[rnd.Next(str.Length)]);
  74.     Thread.Sleep(interval);
  75. }
  76. Console.ReadLine();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement