using System.Collections.Generic;
public static void Main()
int[] values = new int[] {0, 1};
double total_count_of_available_safehackers_per_safe = 300;
int count_the_users_who_has_a_safehacker = 0;
for (int i = 1; i <= 1000; i++)
double v = Math.Round((count_the_users_who_has_a_safehacker * 100) / total_count_of_available_safehackers_per_safe, 2);
chance = chance < 0 ? 0 : chance;
var probs = new int[] {(int)(100 - chance), (int)(chance)};
var r_value = Randomize(values, probs);
count_the_users_who_has_a_safehacker++;
Console.WriteLine(string.Format("Chance - {0}", chance));
Console.WriteLine(string.Format("v - {0}", v));
Console.WriteLine(string.Format("Total count of safehackers - {0}", count_the_users_who_has_a_safehacker));
public static T Randomize<T>(T[] values, int[] probs)
return values[Randomize(probs)];
private static int Randomize(int[] probs)
var random = new Random();
int[] prefix = new int[n];
prefix[i] = prefix[i - 1] + probs[i];
int r = (random.Next() % prefix[n - 1]) + 1;
int indexc = FindCeil(prefix, r, 0, n - 1);
private static int FindCeil(int[] values, int r, int l, int h)
mid = l + ((h - l) >> 1);
return (values[l] >= r) ? l : -1;