selectValueFromList()

in wasm/wasm-sharding-js/sharding/strgen.js [568:611]


    selectValueFromList(defined_no_of_chars, character_index = 0, allow_duplicates = false, output = "") { // pick a random value from the generated_value_list and do this quantifier_value number of times
        if (character_index < this.quantifier_value) {
            var random_value = Math.floor(Math.random() * this.generated_value_list.length);

            if (this.generated_value_list[random_value] != undefined) {
                output += this.generated_value_list[random_value]
                this.createLogEntry("Selected value", this.generated_value_list[random_value]);
            } else {
                if (output == "") {
                    this.outputWarning("No value was returned. Please check the template.");
                    if (this.generated_value_list.length == 0) {
                        this.createLogEntry("<b>Ending value selection and continuing generation...</b>");
                        character_index = this.quantifier_value;
                    }                 
                }
            }

            if (allow_duplicates == false) {
                var value = this.generated_value_list[random_value];

                this.removeValueFromList(value, random_value, true);
                if (this.allow_multiple_instances == false) {
                    this.removeValueFromList(value);
                    if (this.ignore_duplicate_case == true && value.match(/[a-zA-Z]/)) {
                        var value_upper = value.toUpperCase();
                        var value_lower = value.toLowerCase();

                        if (value != value_lower) {
                            value = value_lower;
                        } else {
                            value = value_upper;
                        }

                        this.removeValueFromList(value);
                    }
                }
            }

            return this.selectValueFromList(this.quantifier_value, character_index+=1, allow_duplicates, output);
        } else {
            this.generated_value_list = [];
            return output;
        }
    };