<commit_before>//
//  Random.swift
//  SwiftCheck
//
//  Created by <NAME> on 8/3/14.
//  Copyright (c) 2015 TypeLift. All rights reserved.
//

import func Darwin.time
import func Darwin.clock

/// Provides a standard interface to an underlying Random Value Generator of any type.  It is
/// analogous to `GeneratorType`, but rather than consume a sequence it uses sources of randomness
/// to generate values indefinitely.
public protocol RandomGeneneratorType {
	/// The next operation returns an Int that is uniformly distributed in the range returned by 
	/// `genRange` (including both end points), and a new generator.
	var next : (Int, Self) { get }
	/// The genRange operation yields the range of values returned by the generator.
	///
	/// This property must return integers in ascending order.
	var genRange : (Int, Int) { get }
	/// Splits the receiver into two distinct random value generators.
	var split : (Self, Self) { get }
}

/// A library-provided standard random number generator.
public let standardRNG : StdGen = mkStdRNG(time(nil))

/// 
public struct StdGen : RandomGeneneratorType {
	let seed1 : Int
	let seed2 : Int

	/// Creates a
	public init(replaySeed : Int) {
		func mkStdGen32(sMaybeNegative : Int) -> StdGen {
			let s       = sMaybeNegative & Int.max
			let (q, s1) = (s / 2147483562, s % 2147483562)
			let s2      = q % 2147483398
			return StdGen((s1+1), (s2+1))
		}
		self = mkStdGen32(replaySeed)
	}

	init(_ seed1 : Int, _ seed2 : Int) {
		self.seed1 = seed1
		self.seed2 = seed2
	}

	public var next : (Int, StdGen) {
		let s1 = self.seed1
		let s2 = self.seed2

		let k    = s1 / 53668
		let s1_  = 40014 * (s1 - k * 53668) - k * 12211
		let s1__ = s1_ < 0 ? s1_ + 2147483563 : s1_

		let k_   = s2 / 52774
		let s2_  = 40692 * (s2 - k_ * 52774) - k_ * 3791
		let s2__ = s2_ < 0 ? s2_ + 2147483399 : s2_

		let z    = s1__ - s2__<commit_msg>Document random<commit_after>//
//  Random.swift
//  SwiftCheck
//
//  Created by <NAME> on 8/3/14.
//  Copyright (c) 2015 TypeLift. All rights reserved.
//

import func Darwin.time
import func Darwin.clock

/// Provides a standard interface to an underlying Random Value Generator of any type.  It is
/// analogous to `GeneratorType`, but rather than consume a sequence it uses sources of randomness
/// to generate values indefinitely.
public protocol RandomGeneneratorType {
	/// The next operation returns an Int that is uniformly distributed in the range returned by 
	/// `genRange` (including both end points), and a new generator.
	var next : (Int, Self) { get }
	/// The genRange operation yields the range of values returned by the generator.
	///
	/// This property must return integers in ascending order.
	var genRange : (Int, Int) { get }
	/// Splits the receiver into two distinct random value generators.
	var split : (Self, Self) { get }
}

/// A library-provided standard random number generator.
public let standardRNG : StdGen = mkStdRNG(time(nil))

/// `StdGen` represents a pseudo-random number generator. The library makes it possible to generate
/// repeatable results, by starting with a specified initial random number generator, or to get 
/// different results on each run by using the system-initialised generator or by supplying a seed 
/// from some other source.
public struct StdGen : RandomGeneneratorType {
	let seed1 : Int
	let seed2 : Int

	/// Creates a `StdGen` initialized at the given seed.
	public init(replaySeed : Int) {
		func mkStdGen32(sMaybeNegative : Int) -> StdGen {
			let s       = sMaybeNegative & Int.max
			let (q, s1) = (s / 2147483562, s % 2147483562)
			let s2      = q % 2147483398
			return StdGen((s1 + 1), (s2 + 1))
		}
		self = mkStdGen32(replaySeed)
	}

	init(_ seed1 : Int, _ seed2 : Int) {
		self.seed1 = seed1
		self.seed2 = seed2
	}

	public var next : (Int, StdGen) {
		let s1 = self.seed1
		let s2 = self.seed2

		let k    = s1 / 53668
		let s1_  = 40014 * (s1 - k * 53668) - k * 12211
		let s1__ = s1_ < 0 ? s1_ + 2147483563 : s1_

		let k_   = s2 / 52774
		let s2_  = 40692 * (s2 - k_ * 52774) - k_ * 3791
		let s2__ = s2_ < 0 ? s2_ + 2147483399 : s2_

		let z    = s1__ - s2__
{'fraction_non_alphanumeric': 0.1021297192642788, 'fraction_numerical': 0.06631171345595353, 'mean_word_length': 2.841078066914498, 'pattern_counts': {'":': 0, '<': 9, '<?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': '3478508', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1383, 'n_words': 528}