RandomExt.cs 556 B

123456789101112131415161718192021
  1. using System;
  2. namespace Quadarax.Foundation.Core.Value.Extensions
  3. {
  4. public static class RandomExt
  5. {
  6. public static bool NextBool(this Random owner, int truePercentage)
  7. {
  8. if (owner == null)
  9. throw new ArgumentNullException(nameof(owner));
  10. if (truePercentage == 0)
  11. return false;
  12. if (truePercentage >= 100)
  13. return true;
  14. var value = owner.Next(0, 100);
  15. return value <= truePercentage;
  16. }
  17. }
  18. }