<commit_before>package stats

import java.util.{ Random => JRandom }
import scala.util.control.Exception.allCatch

private[stats] trait Random {
  def nextDouble: Double
}

private[stats] object Random {

   /** A java7 ThreadLocal-based random */
   lazy val threadLocal = new Random {
    private[this] val rand =
      Class.forName("java.util.concurrent.ThreadLocalRandom")
    private[this] val current =
      rand.getDeclaredMethod("current", null)
    private[this] val next =
      rand.getDeclaredMethod("nextDouble", null)
    private[this] val instance =
      current.invoke(null, null)

    def nextDouble = next.invoke(instance, null).asInstanceOf[Double]
  }

  /** A default jdk-based random */
  lazy val fallback = new Random {
    private[this] lazy val doubles = new JRandom()
    def nextDouble = doubles.nextDouble
  }

  private[this] lazy val impl: Random =
    allCatch.opt(threadLocal).getOrElse(fallback)

  def nextDouble = impl.nextDouble
}
<commit_msg>don't cache invocation to current. we want the thread locals current value<commit_after>package stats

import java.util.{ Random => JRandom }
import scala.util.control.Exception.allCatch

private[stats] trait Random {
  def nextDouble: Double
}

private[stats] object Random {

   /** A java7 ThreadLocal-based random */
   lazy val threadLocal = new Random {
    private[this] val rand =
      Class.forName("java.util.concurrent.ThreadLocalRandom")
    private[this] val current =
      rand.getDeclaredMethod("current", null)
    private[this] val next =
      rand.getDeclaredMethod("nextDouble", null)
    private[this] def instance =
      current.invoke(null, null)

    def nextDouble = next.invoke(instance, null).asInstanceOf[Double]
  }

  /** A default jdk-based random */
  lazy val fallback = new Random {
    private[this] lazy val doubles = new JRandom()
    def nextDouble = doubles.nextDouble
  }

  private[this] lazy val impl: Random =
    allCatch.opt(threadLocal).getOrElse(fallback)

  def nextDouble = impl.nextDouble
}

{'fraction_non_alphanumeric': 0.10261470152935373, 'fraction_numerical': 0.000986679822397632, 'mean_word_length': 3.6836027713625867, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '331513', 'n_tokens_mistral': 612, 'n_tokens_neox': 597, 'n_words': 163}