public UserAgent(string userAgentString, UAPlatform platform, double weight, double cumulative) { this.userAgentString = userAgentString; this.weight = weight; this.cumulative = cumulative; this.platform = platform; }
/// <inheritdoc/> public string Generate(UAPlatform platform) { // Take the correct precomputed cumulative distribution var distribution = distributions[platform]; // Take the maximum value of the cumulative function var max = distribution.Last().cumulative; // Generate a random double up to the previously computed maximum var random = rand.NextDouble() * max; // Return the first user agent with cumulative greater or equal to the random one return(distribution.First(u => u.cumulative >= random).userAgentString); }
private UserAgent[] ComputeDistribution(IEnumerable <UserAgent> agents, UAPlatform platform) { var valid = agents.Where(a => BelongsToPlatform(a.platform, platform)); var distribution = new List <UserAgent>(); double cumulative = 0; foreach (var elem in valid) { cumulative += elem.weight; distribution.Add(new UserAgent(elem.userAgentString, elem.platform, elem.weight, cumulative)); } return(distribution.ToArray()); }
public static string RandomUserAgent(BotData data, UAPlatform platform = UAPlatform.All) { data.Logger.LogHeader(); data.Logger.Log("Getting random UA from the builtin provider"); string ua; try { ua = data.Providers.RandomUA.Generate(platform); } catch { ua = "NO_RANDOM_UA_FOUND"; } data.Logger.Log(ua); return(ua); }
private static bool BelongsToPlatform(UAPlatform current, UAPlatform required) => required switch {