<commit_before>{-# LANGUAGE RankNTypes #-}

module Betty.Token where

import           Import

import qualified Data.List            as L
import           Data.Maybe           (fromMaybe, isJust)
import qualified Data.Text            as T

import           System.Random        (StdGen, randomRIO, randomRs)

import           Database.Persist.Sql (SqlBackend (..))

------------------------------------------------------------------------R

makeToken :: StdGen -> IO Text
makeToken g = fmap T.pack $ scramble $ concat [p1, p2, p3]
    where
        p1 = makeStr 4 ('A', 'Z')
        p2 = makeStr 4 ('a', 'z')
        p3 = makeStr 4 ('0', '9')

        makeStr :: Int -> (Char, Char) -> String
        makeStr len range = take len $ randomRs range g

        -- TODO: benchmark this.
        scramble :: String -> IO String
        scramble [] = return []
        scramble xs = do
            n <- randomRIO (0, length xs - 1)
            let e = xs !! n<commit_msg>Minor: where did that stray 'R' come from?<commit_after>{-# LANGUAGE RankNTypes #-}

module Betty.Token where

import           Import

import qualified Data.List            as L
import           Data.Maybe           (fromMaybe, isJust)
import qualified Data.Text            as T

import           System.Random        (StdGen, randomRIO, randomRs)

import           Database.Persist.Sql (SqlBackend (..))

------------------------------------------------------------------------

makeToken :: StdGen -> IO Text
makeToken g = fmap T.pack $ scramble $ concat [p1, p2, p3]
    where
        p1 = makeStr 4 ('A', 'Z')
        p2 = makeStr 4 ('a', 'z')
        p3 = makeStr 4 ('0', '9')

        makeStr :: Int -> (Char, Char) -> String
        makeStr len range = take len $ randomRs range g

        -- TODO: benchmark this.
        scramble :: String -> IO String
        scramble [] = return []
        scramble xs = do
            n <- randomRIO (0, length xs - 1)
            let e = xs !! n
{'fraction_non_alphanumeric': 0.1767109295199183, 'fraction_numerical': 0.013278855975485188, 'mean_word_length': 1.4185185185185185, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '53932', 'n_tokens_mistral': 587, 'n_tokens_neox': 553, 'n_words': 195}