fork(10) download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. static Random m_Random = new Random();
  6.  
  7. public static void Main()
  8. {
  9. double probability = 0.9;
  10.  
  11. int counter = 0;
  12. int tries = 10;
  13.  
  14. for (int i = 0; i < tries; i++) {
  15. if (CompareWithRandom(probability)) {
  16. counter++;
  17. }
  18. }
  19.  
  20. Console.WriteLine("Probabilty is: " + (counter * 100d / tries).ToString("#0.00") + "%");
  21. }
  22.  
  23. private static bool CompareWithRandom(double probability)
  24. {
  25. return probability >= m_Random.NextDouble();
  26. }
  27. }
Success #stdin #stdout 0.03s 33896KB
stdin
Standard input is empty
stdout
Probabilty is: 90.00%