fork download
  1. using System;
  2.  
  3. class CompleteRandom
  4. {
  5. int[] next;
  6. int min, max;
  7. int count;
  8. Random r = new Random();
  9.  
  10. public CompleteRandom(int _min, int _max)
  11. {
  12. if (_max > _min)
  13. {
  14. min = _max;
  15. max = _min;
  16. }
  17. else
  18. {
  19. min = _min;
  20. max = _max;
  21. }
  22.  
  23. count = max - min;
  24. next = new int[count];
  25.  
  26. for (int i = _min, j = 0; j < count; j++, i++)
  27. next[j] = i;
  28. }
  29.  
  30. public int Value
  31. {
  32. get
  33. {
  34. int index = r.Next() % count;
  35. int result = next[index];
  36. count--;
  37. if (count == 0)
  38. {
  39. count = next.Length;
  40. }
  41. else
  42. {
  43. int tmp = next[index];
  44. next[index] = next[count];
  45. next[count]= tmp;
  46. }
  47. return result;
  48. }
  49. }
  50. }
  51.  
  52.  
  53. public class Test
  54. {
  55. public static void Main()
  56. {
  57. CompleteRandom cr = new CompleteRandom(0, 5);
  58. for (int i = 0; i < 10; i++)
  59. ;//System.Diagnostics.Debug.Write(cr.Value);
  60. }
  61. }
Runtime error #stdin #stdout #stderr 0s 32608KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Unhandled Exception:
System.OverflowException: Number overflow.
  at (wrapper alloc) object:AllocVector (intptr,intptr)
  at CompleteRandom..ctor (Int32 _min, Int32 _max) [0x00000] in <filename unknown>:0 
  at Test.Main () [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.OverflowException: Number overflow.
  at (wrapper alloc) object:AllocVector (intptr,intptr)
  at CompleteRandom..ctor (Int32 _min, Int32 _max) [0x00000] in <filename unknown>:0 
  at Test.Main () [0x00000] in <filename unknown>:0