using System.Collections.Generic;
public static void Main()
int[] values = new int[] {0, 1};
int total_count_of_users_who_has_a_safe = 1;
int 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 remaining_safehachers = total_count_of_available_safehackers_per_safe - count_the_users_who_has_a_safehacker;
double count_users_who_dont_have_a_safehacker = total_count_of_users_who_has_a_safe - count_the_users_who_has_a_safehacker;
double v = Math.Round((remaining_safehachers * 100) / count_users_who_dont_have_a_safehacker, 2);
chance = chance < 0 ? 0 : chance;
var probs = new int[] {(int)v, (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 users - {0}",total_count_of_users_who_has_a_safe));
Console.WriteLine(string.Format("Total count of safehackers - {0}", count_the_users_who_has_a_safehacker));
total_count_of_users_who_has_a_safe++;
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;