<commit_before>package rand

import (
	"math/rand"
	"time"
)

func init() {
	rand.Seed(time.Now().UnixNano())
}

var chars = []byte("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

// String returns a random string of given length
func String(n int) string {
	if n <= 0 {
		return ""
	}

	bytes := make([]byte, n)
	for i := 0; i < n; i++ {
		bytes[i] = chars[rand.Intn(len(chars))]
	}

	return string(bytes)
}<commit_msg>security: replace math/rand with crypto/rand to generate secret strings (#898)<commit_after>package rand

import (
	"crypto/rand"
	"math/big"
)

var chars = []byte("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

// String returns a random string of given length
func String(n int) string {
	if n <= 0 {
		return ""
	}

	bytes := make([]byte, n)
	charsetLen := big.NewInt(int64(len(chars)))
	for i := 0; i < n; i++ {
		c, err := rand.Int(rand.Reader, charsetLen)
		if err != nil {
			panic(err)
		}
		bytes[i] = chars[c.Int64()]
	}

	return string(bytes)
}
{'fraction_non_alphanumeric': 0.15301085883514315, 'fraction_numerical': 0.03060217176702863, 'mean_word_length': 4.147208121827411, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '1839203', 'n_tokens_mistral': 446, 'n_tokens_neox': 396, 'n_words': 96}