<commit_before>// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.


/*
 *	algorithm by
 *	<NAME> and <NAME>
 */

package	rand

// rand, rand31, rand63 - return non-negative random int, int32, int64
// urand32 - return random uint32
// nrand, nrand31, nrand63 - return 0 <= random < n
// frand, frand64, frand32 - return 0 <= random float, float64, float32 < 1

const
(
	LEN	 = 607;
	TAP	 = 273;
	MASK	 = (1<<63)-1;
	A	 = 48271;
	M	 = 2147483647;
	Q	 = 44488;
	R	 = 3399;
)

var
(
	rng_cooked	[LEN]int64;	// cooked random numbers
	rng_vec		[LEN]int64;	// current feedback register
	rng_tap		int;		// index into vector
	rng_feed	int;		// index into vector
)

func
seedrand(x int32) int32
{
	// seed rng x[n+1] = 48271 * x[n] mod (2**31 - 1)
	hi := x / Q;
	lo := x % Q;
	x = A*lo - R*hi;
	if x < 0 {
		x += M;
	}
	return x;
}

export func
srand(seed int32)
{
	rng_tap = 0;
	rng_feed = LEN-TAP;

	seed = seed%M;
	if seed < 0 {
		seed += M;
	}
	if seed == 0 {
		seed = 89482311;
	}

	x := seed;
	for i := -20; i < LEN; i++ {
		x = seedrand(x);
		if i >= 0 {
			var u int64;
			u = int64(x) << 20;
			x = seedrand(x);
			u ^= int64(x) << 10;
			x = seedrand(x);
			u ^= int64(x);
			u ^= rng_cooked[i];
			rng_vec[i] = u & MASK;
		}
	}
}

export func
rand63() int64
{
	rng_tap--;
	if rng_tap < 0 {
		rng_tap += LEN;
	}

	rng_feed--;
	if rng_feed < 0 {
		rng_feed += LEN;
	}

	x := (rng_vec[rng_feed] + rng_vec[rng_tap]) & MASK;
	rng_vec[rng_feed] = x;
	return x;
}

export func
urand32() uint32
{
	return uint32(rand63() >> 31);
}

export func
rand31() int32
{
	return int32(rand63() >> 32);
}

export func
rand() int
{
	u := uint(rand63());
	return int(u << 1 >> 1);	// clear sign bit if int == int32
}

export func
nrand63(n int64) int64
{
	if n <= 0 {
		return 0
	}
	max := int64((1<<63)-1 - (1<<63) % uint64(n));
	v := rand63();
	for v > max {
		v = rand63()
	}
	return v % n
}

export func
nrand31(n int32) int32
{
	return int32(nrand63(int64(n)))
}

export func
nrand(n int) int
{
	return int(nrand63(int64(n)))
}

export func
frand64() float64
{
	x := float64(rand63()) / float64(MASK);
	for x >= 1 {
		x = float64(rand63()) / float64(MASK);
	}
	return x;
}

export func
frand32() float32
{
	return float32(frand64())
}

export func
frand() float
{
	return float(frand64())
}

func
init()
{
	// the state of the rng
	// after 780e10 iterations

	rng_cooked[  0] = 5041579894721019882;
	rng_cooked[  1] = 4646389086726545243;
	rng_cooked[  2] = 1395769623340756751;
	rng_cooked[  3] = 5333664234075297259;
	rng_cooked[  4] = 2875692520355975054;
	rng_cooked[  5] = 9033628115061424579;
	rng_cooked[  6] = 7143218595135194537;
	rng_cooked[  7] = 4812947590706362721;
	rng_cooked[  8] = 7937252194349799378;
	rng_cooked[  9] = 5307299880338848416;
	rng_cooked[ 10] = 8209348851763925077;
	rng_cooked[ 11] = 2115741599318814044;
	rng_cooked[ 12] = 4593015457530856296;
	rng_cooked[ 13] = 8140875735541888011;
	rng_cooked[ 14] = 3319429241265089026;
	rng_cooked[ 15] = 8619815648190321034;
	rng_cooked[ 16] = 1727074043483619500;
	rng_cooked[ 17] =  113108499721038619;
	rng_cooked[ 18] = 4569519971459345583;
	rng_cooked[ 19] = 5062833859075314731;
	rng_cooked[ 20] = 2387618771259064424;
	rng_cooked[ 21] = 2716131344356686112;
	rng_cooked[ 22] = 6559392774825876886;<commit_msg>random permutation function func perm(n int) *map[int]int<commit_after>// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.


/*
 *	algorithm by
 *	<NAME> and <NAME>
 */

package	rand

// rand, rand31, rand63 - return non-negative random int, int32, int64
// urand32 - return random uint32
// nrand, nrand31, nrand63 - return 0 <= random < n
// frand, frand64, frand32 - return 0 <= random float, float64, float32 < 1
// perm gives a random permutation map[int]int

const
(
	LEN	 = 607;
	TAP	 = 273;
	MASK	 = (1<<63)-1;
	A	 = 48271;
	M	 = 2147483647;
	Q	 = 44488;
	R	 = 3399;
)

var
(
	rng_cooked	[LEN]int64;	// cooked random numbers
	rng_vec		[LEN]int64;	// current feedback register
	rng_tap		int;		// index into vector
	rng_feed	int;		// index into vector
)

func
seedrand(x int32) int32
{
	// seed rng x[n+1] = 48271 * x[n] mod (2**31 - 1)
	hi := x / Q;
	lo := x % Q;
	x = A*lo - R*hi;
	if x < 0 {
		x += M;
	}
	return x;
}

export func
srand(seed int32)
{
	rng_tap = 0;
	rng_feed = LEN-TAP;

	seed = seed%M;
	if seed < 0 {
		seed += M;
	}
	if seed == 0 {
		seed = 89482311;
	}

	x := seed;
	for i := -20; i < LEN; i++ {
		x = seedrand(x);
		if i >= 0 {
			var u int64;
			u = int64(x) << 20;
			x = seedrand(x);
			u ^= int64(x) << 10;
			x = seedrand(x);
			u ^= int64(x);
			u ^= rng_cooked[i];
			rng_vec[i] = u & MASK;
		}
	}
}

export func
rand63() int64
{
	rng_tap--;
	if rng_tap < 0 {
		rng_tap += LEN;
	}

	rng_feed--;
	if rng_feed < 0 {
		rng_feed += LEN;
	}

	x := (rng_vec[rng_feed] + rng_vec[rng_tap]) & MASK;
	rng_vec[rng_feed] = x;
	return x;
}

export func
urand32() uint32
{
	return uint32(rand63() >> 31);
}

export func
rand31() int32
{
	return int32(rand63() >> 32);
}

export func
rand() int
{
	u := uint(rand63());
	return int(u << 1 >> 1);	// clear sign bit if int == int32
}

export func
nrand63(n int64) int64
{
	if n <= 0 {
		return 0
	}
	max := int64((1<<63)-1 - (1<<63) % uint64(n));
	v := rand63();
	for v > max {
		v = rand63()
	}
	return v % n
}

export func
nrand31(n int32) int32
{
	return int32(nrand63(int64(n)))
}

export func
nrand(n int) int
{
	return int(nrand63(int64(n)))
}

export func
frand64() float64
{
	x := float64(rand63()) / float64(MASK);
	for x >= 1 {
		x = float64(rand63()) / float64(MASK);
	}
	return x;
}

export func
frand32() float32
{
	return float32(frand64())
}

export func
frand() float
{
	return float(frand64())
}

export func
perm(n int) *map[int]int
{
	m := new(map[int]int);
	for i:=0; i<n; i++ {
		m[i] = i;
	}
	for i:=0; i<n; i++ {
		j := nrand(n);
		t := m[i];
		m[i] = m[j];
		m[j] = t;
	}
	return m;
}

func
init()
{
	// the state of the rng
	// after 780e10 iterations

	rng_cooked[  0] = 5041579894721019882;
	rng_cooked[  1] = 4646389086726545243;
	rng_cooked[  2] = 1395769623340756751;
	rng_cooked[  3] = 5333664234075297259;
	rng_cooked[  4] = 2875692520355975054;
	rng_cooked[  5] = 9033628115061424579;
	rng_cooked[  6] = 7143218595135194537;
	rng_cooked[  7] = 4812947590706362721;
	rng_cooked[  8] = 7937252194349799378;
	rng_cooked[  9] = 5307299880338848416;
	rng_cooked[ 10] = 8209348851763925077;
	rng_cooked[ 11] = 2115741599318814044;
	rng_cooked[ 12] = 4593015457530856296;
	rng_cooked[ 13] = 8140875735541888011;
	rng_cooked[ 14] = 3319429241265089026;
	rng_cooked[ 15] = 8619815648190321034;
	rng_cooked[ 16] = 1727074043483619500;
	rng_cooked[ 17] =  113108499721038619;
	rng_cooked[ 18] = 4569519971459345583;
	rng_cooked[ 19] = 5062833859075314731;
	rng_cooked[ 20] = 2387618771259064424;
	rng_cooked[ 21] = 2716131344356686112;
	rng_cooked[ 22] = 6559392774825876886;
{'fraction_non_alphanumeric': 0.14935525010627745, 'fraction_numerical': 0.19498370412356525, 'mean_word_length': 3.351418002466091, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 25, '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': '1304087', 'n_tokens_mistral': 4245, 'n_tokens_neox': 3296, 'n_words': 798}