<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pigeon.Routing
{
    class Random
    {
    }
}<commit_msg>Added RandomGroup router<commit_after>﻿using Pigeon.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Pigeon.Routing
{
    //TODO: there has to be a better way to do this?
    public class ThreadSafeRandom
    {
        private static readonly Random _global = new Random();
        [ThreadStatic]
        private static Random _local;

        static ThreadSafeRandom()
        {
            if (_local == null)
            {
                int seed;
                lock (_global)
                {
                    seed = _global.Next();
                }
                _local = new Random(seed);
            }
        }
        public static int Next(int maxValue)
        {
            return _local.Next(maxValue);
        }
    }

    public class RandomLogic : RoutingLogic
    {
        public override Routee Select(object message, Routee[] routees)
        {
            if (routees == null || routees.Length == 0)
            {
                return Routee.NoRoutee;
            }
            else
            {
                return routees[ThreadSafeRandom.Next(routees.Length-1) % routees.Length];
            }
        }
    }

    public class RandomGroup : Group
    {
        public RandomGroup(Config config)
            : base(config.GetStringList("routees.paths"))
        {

        }
        public RandomGroup(params string[] paths)
            : base(paths)
        {

        }
        public RandomGroup(IEnumerable<string> paths)
            : base(paths)
        {

        }

        public override RoutingLogic GetLogic()
        {
            return new RoundRobinLogic();
        }
    }
}
{'fraction_non_alphanumeric': 0.0835897435897436, 'fraction_numerical': 0.0010256410256410256, 'mean_word_length': 1.5944148936170213, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2452445', 'n_tokens_mistral': 528, 'n_tokens_neox': 515, 'n_words': 125}