<commit_before>using System;

namespace ACE.Common
{
    // important class, ensure unit tests pass for this
    // todo: implement exactly the way AC handles it.. which we'll never know unless we get original source code
    public static class ThreadSafeRandom
    {
        private static readonly object randomMutex = new object();
        private static readonly Random random = new Random();

        /// <summary>
        /// Returns a random floating-point number between min and max, inclusive
        /// </summary>
        /// <param name="min">The minimum possible value to return</param>
        /// <param name="max">The maximum possible value to return</param>
        public static float Next(float min, float max)
        {
            lock (randomMutex)
                return (float)(random.NextDouble() * (max - min) + min);
        }

        /// <summary>
        /// Returns a random integer between min and max, inclusive
        /// </summary>
        /// <param name="min">The minimum possible value to return</param>
        /// <param name="max">The maximum possible value to return</param>
        public static int Next(int min, int max)
        {
            lock (randomMutex)
                return random.Next(min, max + 1);
        }
    }
}
<commit_msg>Switch ThreadSafeRandom from lock to ThreadLocal<Random> (#2432)<commit_after>using System;
using System.Threading;

namespace ACE.Common
{
    // important class, ensure unit tests pass for this
    // todo: implement exactly the way AC handles it.. which we'll never know unless we get original source code
    public static class ThreadSafeRandom
    {
        static readonly ThreadLocal<Random> random = new ThreadLocal<Random>(() => new Random());

        /// <summary>
        /// Returns a random floating-point number between min and max, inclusive
        /// </summary>
        /// <param name="min">The minimum possible value to return</param>
        /// <param name="max">The maximum possible value to return</param>
        public static float Next(float min, float max)
        {
            return (float)(random.Value.NextDouble() * (max - min) + min);
        }

        /// <summary>
        /// Returns a random integer between min and max, inclusive
        /// </summary>
        /// <param name="min">The minimum possible value to return</param>
        /// <param name="max">The maximum possible value to return</param>
        public static int Next(int min, int max)
        {
            return random.Value.Next(min, max + 1);
        }
    }
}

{'fraction_non_alphanumeric': 0.10881435257410296, 'fraction_numerical': 0.00234009360374415, 'mean_word_length': 2.1823821339950373, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 31, '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': '6067471', 'n_tokens_mistral': 636, 'n_tokens_neox': 623, 'n_words': 250}