fork(1) download
  1. using System;
  2. using System.Security.Cryptography;
  3.  
  4. public static class Test
  5. {
  6. private static readonly RNGCryptoServiceProvider Generator = new RNGCryptoServiceProvider();
  7.  
  8. public static byte GetByte()
  9. {
  10. var buffer = new byte[1];
  11. Generator.GetBytes(buffer);
  12. return buffer[0];
  13. }
  14.  
  15. public static int GetInt32(int minimum, int maximum)
  16. {
  17.  
  18. return (int) (minimum + (Sample() * (maximum - minimum)));
  19. }
  20.  
  21. public static decimal Sample()
  22. {
  23. var buffer = new byte[8];
  24. Generator.GetBytes(buffer);
  25. return (BitConverter.ToUInt64(buffer, 0) & 0x7FFFFFFFFFFFFFFF) / (decimal) long.MaxValue;
  26. }
  27.  
  28. public static void Main()
  29. {
  30. Console.WriteLine("Hello World");
  31. int[] counters = new int[4];
  32. for (int i = 0; i < 10000; i++)
  33. {
  34. counters[GetInt32(0, 3)]++;
  35. }
  36. for (int i = 0; i < 4; i++)
  37. {
  38. Console.WriteLine("Value " + i + " counted " + counters[i]);
  39. }
  40. }
  41.  
  42. }
Success #stdin #stdout 0.08s 33776KB
stdin
Standard input is empty
stdout
Hello World
Value 0 counted 3314
Value 1 counted 3374
Value 2 counted 3312
Value 3 counted 0