<commit_before>! Copyright (C) 2005, 2008 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
! mersenne twister based on 
! http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/mt19937ar.c

USING: arrays kernel math namespaces sequences system init
accessors math.ranges random ;
IN: random.mersenne-twister

<PRIVATE

: curry2 ( w quot1 quot2 -- quot1 quot2 )
    >r over r> [ curry ] 2bi@ ;

TUPLE: mersenne-twister seq i ;

: mt-n 624 ; inline
: mt-m 397 ; inline
: mt-a HEX: 9908b0df ; inline
: mt-hi HEX: 80000000 bitand ; inline
: mt-lo HEX: 7fffffff bitand ; inline
: wrap ( x n -- y ) 2dup >= [ - ] [ drop ] if ; inline
: mt-wrap ( x -- y ) mt-n wrap ; inline

: set-generated ( y from-elt to seq -- )
    >r >r >r [ 2/ ] [ odd? mt-a 0 ? ] bi
    r> bitxor bitxor r> r> set-nth ; inline

: calculate-y ( y1 y2 mt -- y )
    [ nth mt-hi ] [ nth mt-lo ] curry2 bi* bitor ; inline

: (mt-generate) ( n mt-seq -- y to from-elt )
    [ >r dup 1+ mt-wrap r> calculate-y ]
    [ >r mt-m + mt-wrap r> nth ]
    [ drop ] 2tri ;

: mt-generate ( mt -- )
    [ >r mt-n r> seq>> [ [ (mt-generate) ] keep set-generated ] curry each ]<commit_msg>Add inline declaration<commit_after>! Copyright (C) 2005, 2008 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
! mersenne twister based on 
! http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/mt19937ar.c

USING: arrays kernel math namespaces sequences system init
accessors math.ranges random ;
IN: random.mersenne-twister

<PRIVATE

: curry2 ( w quot1 quot2 -- quot1 quot2 )
    >r over r> [ curry ] 2bi@ ; inline

TUPLE: mersenne-twister seq i ;

: mt-n 624 ; inline
: mt-m 397 ; inline
: mt-a HEX: 9908b0df ; inline
: mt-hi HEX: 80000000 bitand ; inline
: mt-lo HEX: 7fffffff bitand ; inline
: wrap ( x n -- y ) 2dup >= [ - ] [ drop ] if ; inline
: mt-wrap ( x -- y ) mt-n wrap ; inline

: set-generated ( y from-elt to seq -- )
    >r >r >r [ 2/ ] [ odd? mt-a 0 ? ] bi
    r> bitxor bitxor r> r> set-nth ; inline

: calculate-y ( y1 y2 mt -- y )
    [ nth mt-hi ] [ nth mt-lo ] curry2 bi* bitor ; inline

: (mt-generate) ( n mt-seq -- y to from-elt )
    [ >r dup 1+ mt-wrap r> calculate-y ]
    [ >r mt-m + mt-wrap r> nth ]
    [ drop ] 2tri ;

: mt-generate ( mt -- )
    [ >r mt-n r> seq>> [ [ (mt-generate) ] keep set-generated ] curry each ]
{'fraction_non_alphanumeric': 0.15555555555555556, 'fraction_numerical': 0.04358974358974359, 'mean_word_length': 2.5362537764350455, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '3222176', 'n_tokens_mistral': 1016, 'n_tokens_neox': 925, 'n_words': 287}