<commit_before><commit_msg>Added object to produce random but cyclic sequences from arrays.<commit_after>
const RG = require('./rg');
const Random = require('./random');

const RNG = Random.getRNG();

/* Given an array, cycles through all of its values in random order, but is
 * guaranteed to eventually return each value. */
const RandomCyclic = function(arr) {
    if (!arr || arr.length === 0) {
        RG.err('RandomCyclic', 'new',
            'array with length > 0 must be given');
    }
    this.arr = arr;
    this.reset();
    this.length = arr.length;
};

RandomCyclic.prototype.reset = function() {
    this.indicesLeft = [];
    this.arr.forEach((item, index) => {
        this.indicesLeft.push(index);
    });
    this._prevValue = null;
    this._currValue = null;
};

RandomCyclic.prototype.prev = function() {
    return this._prevValue;
};

RandomCyclic.prototype.next = function() {
    if (this.indicesLeft.length === 0) {
        this.reset();
    }
    const index = RNG.arrayGetRand(this.indicesLeft);
    // Remove just found index from indicesLeft
    this.indicesLeft = this.indicesLeft.filter(val => val !== index);

    this._prevValue = this._currValue;
    this._currValue = this.arr[index];
    return this._currValue;
};

module.exports = RandomCyclic;
{'fraction_non_alphanumeric': 0.13929961089494164, 'fraction_numerical': 0.0023346303501945525, 'mean_word_length': 3.161812297734628, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '5366209', 'n_tokens_mistral': 394, 'n_tokens_neox': 379, 'n_words': 101}