<commit_before>// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/*============================================================
**
**
**
** Purpose: A random number generator.
**
** 
===========================================================*/
namespace System {

    using System;
    using System.Runtime;
    using System.Runtime.CompilerServices;
    using System.Globalization;
    using System.Diagnostics.Contracts;

    [System.Runtime.InteropServices.ComVisible(true)]
    [Serializable]
    public class Random {
      //
      // Private Constants 
      //
      private const int MBIG =  Int32.MaxValue;
      private const int MSEED = 161803398;
      private const int MZ = 0;
    
      
      //
      // Member Variables
      //
      private int inext;
      private int inextp;
      private int[] SeedArray = new int[56];
    
      //
      // Public Constants
      //
    
      //
      // Native Declarations
      //
    
      //
      // Constructors
      //
      
      /*=========================================================================================
      **Action: Initializes a new instance of the Random class, using a default seed value
      ===========================================================================================*/
      public Random() 
        : this(GenerateSeed()) {
      }
      
      /*=========================================================================================
      **Action: Initializes a new instance of the Random class, using a the specified seed value
      ===========================================================================================*/
      public Random(int Seed) {
        int ii;
        int mj, mk;
    
        //Initialize our Seed array.
        int subtraction = (Seed == Int32.MinValue) ? Int32.MaxValue : Math.Abs(Seed);
        mj = MSEED - subtraction;
        SeedArray[55]=mj;
        mk=1;
        for (int i=1; i<55; i++) {  //Apparently the range [1..55] is special (Knuth) and so we're wasting the 0'th position.
          ii = (21*i)%55;
          SeedArray[ii]=mk;
          mk = mj - mk;
          if (mk<0) mk+=MBIG;
          mj=SeedArray[ii];
        }
        for (int k=1; k<5; k++) {
          for (int i=1; i<56; i++) {
        SeedArray[i] -= SeedArray[1+(i+30)%55];
        if (SeedArray[i]<0) SeedArray[i]+=MBIG;
          }
        }
        inext=0;
        inextp = 21;
        Seed = 1;
      }

      //
      // Package Private Methods
      //

      /*====================================Sample====================================
      **Action: Return a new random number [0..1) and reSeed the Seed array.
      **Returns: A double [0..1)
      **Arguments: None
      **Exceptions: None
      ==============================================================================*/
      protected virtual double Sample() {
          //Including this division at the end gives us significantly improved
          //random number distribution.
          return (InternalSample()*(1.0/MBIG));
      }
    
      private int InternalSample() {
          int retVal;
          int locINext = inext;
          int locINextp = inextp;

          if (++locINext >=56) locINext=1;
          if (++locINextp>= 56) locINextp = 1;
          
          retVal = SeedArray[locINext]-SeedArray[locINextp];

          if (retVal == MBIG) retVal--;          
          if (retVal<0) retVal+=MBIG;
          
          SeedArray[locINext]=retVal;

          inext = locINext;
          inextp = locINextp;
                    
          return retVal;
      }


      [ThreadStatic]
      private static Random t_threadRandom;
      private static Random s_globalRandom = new Random(GenerateGlobalSeed());

      /*=====================================GenerateSeed=====================================
      **Returns: An integer that can be used as seed values for consecutively
                 creating lots of instances on the same thread within a short period of time.
      ========================================================================================*/
      private static int GenerateSeed() {
          if (t_threadRandom == null) {
              int seed;
              lock (s_globalRandom) {
                  seed = s_globalRandom.Next();
              }
              t_threadRandom = new Random(seed);
          }
          return t_threadRandom.Next();
      }

      /*==================================GenerateGlobalSeed====================================
      **Action:  Creates a number to use as global seed.
      **Returns: An integer that is safe to use as seed values for thread-local seed generators.
      ==========================================================================================*/
      private static int GenerateGlobalSeed() {
          return Guid.NewGuid().GetHashCode();
      }
<commit_msg>Addressed PR feedback.<commit_after>// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/*============================================================
**
**
**
** Purpose: A random number generator.
**
** 
===========================================================*/
namespace System {

    using System;
    using System.Runtime;
    using System.Runtime.CompilerServices;
    using System.Globalization;
    using System.Diagnostics.Contracts;

    [System.Runtime.InteropServices.ComVisible(true)]
    [Serializable]
    public class Random {
      //
      // Private Constants 
      //
      private const int MBIG =  Int32.MaxValue;
      private const int MSEED = 161803398;
      private const int MZ = 0;
    
      
      //
      // Member Variables
      //
      private int inext;
      private int inextp;
      private int[] SeedArray = new int[56];
    
      //
      // Public Constants
      //
    
      //
      // Native Declarations
      //
    
      //
      // Constructors
      //
      
      /*=========================================================================================
      **Action: Initializes a new instance of the Random class, using a default seed value
      ===========================================================================================*/
      public Random() 
        : this(GenerateSeed()) {
      }
      
      /*=========================================================================================
      **Action: Initializes a new instance of the Random class, using a specified seed value
      ===========================================================================================*/
      public Random(int Seed) {
        int ii;
        int mj, mk;
    
        //Initialize our Seed array.
        int subtraction = (Seed == Int32.MinValue) ? Int32.MaxValue : Math.Abs(Seed);
        mj = MSEED - subtraction;
        SeedArray[55]=mj;
        mk=1;
        for (int i=1; i<55; i++) {  //Apparently the range [1..55] is special (Knuth) and so we're wasting the 0'th position.
          ii = (21*i)%55;
          SeedArray[ii]=mk;
          mk = mj - mk;
          if (mk<0) mk+=MBIG;
          mj=SeedArray[ii];
        }
        for (int k=1; k<5; k++) {
          for (int i=1; i<56; i++) {
        SeedArray[i] -= SeedArray[1+(i+30)%55];
        if (SeedArray[i]<0) SeedArray[i]+=MBIG;
          }
        }
        inext=0;
        inextp = 21;
        Seed = 1;
      }

      //
      // Package Private Methods
      //

      /*====================================Sample====================================
      **Action: Return a new random number [0..1) and reSeed the Seed array.
      **Returns: A double [0..1)
      **Arguments: None
      **Exceptions: None
      ==============================================================================*/
      protected virtual double Sample() {
          //Including this division at the end gives us significantly improved
          //random number distribution.
          return (InternalSample()*(1.0/MBIG));
      }
    
      private int InternalSample() {
          int retVal;
          int locINext = inext;
          int locINextp = inextp;

          if (++locINext >=56) locINext=1;
          if (++locINextp>= 56) locINextp = 1;
          
          retVal = SeedArray[locINext]-SeedArray[locINextp];

          if (retVal == MBIG) retVal--;          
          if (retVal<0) retVal+=MBIG;
          
          SeedArray[locINext]=retVal;

          inext = locINext;
          inextp = locINextp;
                    
          return retVal;
      }


      [ThreadStatic]
      private static Random t_threadRandom;
      private static readonly Random s_globalRandom = new Random(GenerateGlobalSeed());

      /*=====================================GenerateSeed=====================================
      **Returns: An integer that can be used as seed values for consecutively
                 creating lots of instances on the same thread within a short period of time.
      ========================================================================================*/
      private static int GenerateSeed() {
          Random rnd = t_threadRandom;
          if (rnd == null) {
              int seed;
              lock (s_globalRandom) {
                  seed = s_globalRandom.Next();
              }
              rnd = new Random(seed);
              t_threadRandom = rnd;
          }
          return rnd.Next();
      }

      /*==================================GenerateGlobalSeed====================================
      **Action:  Creates a number to use as global seed.
      **Returns: An integer that is safe to use as seed values for thread-local seed generators.
      ==========================================================================================*/
      private static int GenerateGlobalSeed() {
          return Guid.NewGuid().GetHashCode();
      }

{'fraction_non_alphanumeric': 0.2710510747387103, 'fraction_numerical': 0.012029185564977321, 'mean_word_length': 2.2478386167146973, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 7, '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': '5304587', 'n_tokens_mistral': 2647, 'n_tokens_neox': 2418, 'n_words': 729}