<commit_before>from rpython.rlib import rrandom, rarithmetic

from pycket.prims.expose import default, expose, expose_val
from pycket import values
from pycket import vector as values_vector

# XXX for now just always use a global rng

rng = rrandom.Random()

@expose("random", [default(values.W_Fixnum, None)])
def random(w_k):
    if w_k is None:
        # random flonum
        return values.W_Flonum(rng.random())
    upper = w_k.value
    return values.W_Fixnum(int(rng.random() * upper))

@expose("random-seed", [values.W_Fixnum])
def random_seed(seed):
    key = [rarithmetic.r_uint(seed.value)]
    rng.init_by_array(key)
    return values.w_void

@expose("make-pseudo-random-generator", [])
def make_pseudo_random_generator():
    return values.W_PseudoRandomGenerator()

current_pseudo_random_generator = values.W_Parameter(values.W_PseudoRandomGenerator())
expose_val("current-pseudo-random-generator", current_pseudo_random_generator)

@expose("pseudo-random-generator->vector", [values.W_PseudoRandomGenerator])
def pseudo_random_generator_to_vector(gen):
    return values_vector.W_Vector.fromelements([])

@expose("vector->pseudo-random-generator", [values.W_PseudoRandomGenerator, default(values.W_MVector, None)])<commit_msg>Better implementation of random<commit_after>from rpython.rlib import rrandom, rarithmetic

from pycket.prims.expose import default, expose, expose_val
from pycket              import values
from pycket              import vector as values_vector
from pycket.error        import SchemeException

# XXX for now just always use a global rng

rng = rrandom.Random()

@expose("random")
def random(args):
    if not args:
        # random flonum
        return values.W_Flonum(rng.random())
    a1 = args[0]
    if isinstance(a1, values.W_Fixnum):
        upper = a1.value
        return values.W_Fixnum(int(rng.random() * upper))
    if isinstance(a1, values.W_PseudoRandomGenerator):
        return values.W_Flonum(rng.random())
    raise SchemeException("random: invalid arguments")

@expose("random-seed", [values.W_Fixnum])
def random_seed(seed):
    key = [rarithmetic.r_uint(seed.value)]
    rng.init_by_array(key)
    return values.w_void

@expose("make-pseudo-random-generator", [])
def make_pseudo_random_generator():
    return values.W_PseudoRandomGenerator()

current_pseudo_random_generator = values.W_Parameter(values.W_PseudoRandomGenerator())
expose_val("current-pseudo-random-generator", current_pseudo_random_generator)

@expose("pseudo-random-generator->vector", [values.W_PseudoRandomGenerator])
def pseudo_random_generator_to_vector(gen):
    return values_vector.W_Vector.fromelements([])

@expose("vector->pseudo-random-generator", [values.W_PseudoRandomGenerator, default(values.W_MVector, None)])
{'fraction_non_alphanumeric': 0.11090974990938746, 'fraction_numerical': 0.001812250815512867, 'mean_word_length': 5.202247191011236, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6307149', 'n_tokens_mistral': 903, 'n_tokens_neox': 890, 'n_words': 173}