/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2017-2020 Yegor Bugayenko
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package org.cactoos.text;

import java.security.SecureRandom;
import java.util.List;
import java.util.Random;
import org.cactoos.Scalar;
import org.cactoos.iterable.IterableOf;
import org.cactoos.iterable.RangeOf;
import org.cactoos.iterable.Shuffled;
import org.cactoos.iterator.Cycled;
import org.cactoos.iterator.Sliced;
import org.cactoos.list.ListOf;

/**
 * Randomized text.
 *
 * <p>There is no thread-safety guarantee.
 *
 * @since 0.32
 */
public final class Randomized extends TextEnvelope {

    /**
     * Max length of generated text (if no length is specified).
     */
    private static final int MAX_RANDOM_LENGTH = 255;

    /**
     * Ctor.
     */
    public Randomized() {
        this(
            () -> new SecureRandom().nextInt(
                Randomized.MAX_RANDOM_LENGTH - 1
            ) + 1
        );
    }

    /**
     * Ctor.
     * @param len Length of generated text.
     */
    public Randomized(final Integer len) {
        this(() -> len);
    }

    /**
     * Ctor.
     * @param len Length of generated text.
     */
    public Randomized(final Scalar<Integer> len) {
        this(
            new RangeOf<>(
                '!', '~', ch -> (char) (ch + 1)
            ),
            len
        );
    }

    /**
     * Ctor.
     * @param chrs Array of characters allowed for generating.
     */
    public Randomized(final Character... chrs) {
        this(new ListOf<>(chrs));
    }

    /**
     * Ctor.
     * @param chrs List of characters allowed for generating.
     */
    public Randomized(final List<Character> chrs) {
        this(
            chrs,
            () -> new SecureRandom().nextInt(
                Randomized.MAX_RANDOM_LENGTH - 1
            ) + 1
        );
    }

    /**
     * Ctor.
     * @param len Length of generated text.
     * @param chrs Array of characters allowed for generating.
     */
    public Randomized(final Integer len, final Character... chrs) {
        this(() -> len, chrs);
    }

    /**
     * Ctor.
     * @param len Length of generated text.
     * @param chrs Array of characters allowed for generating.
     */
    public Randomized(final Scalar<Integer> len, final Character... chrs) {
        this(new ListOf<>(chrs), len);
    }

    /**
     * Ctor.
     * @param chrs List of characters allowed for generating.
     * @param len Length of generated text.
     */
    public Randomized(final List<Character> chrs, final Scalar<Integer> len) {
        this(chrs, len, new SecureRandom());
    }

    /**
     * Ctor.
     * @param chrs List of characters allowed for generating.
     * @param len Length of generated text.
     * @param rnd Characters index randomizer.
     */
    public Randomized(final List<Character> chrs, final Scalar<Integer> len, final Random rnd) {
        super(
            new TextOf(
                () -> {
                    final int length = len.value();
                    final StringBuilder builder = new StringBuilder(length);
                    final int bound = chrs.size();
                    for (int index = 0; index < length; index = index + 1) {
                        builder.append(chrs.get(rnd.nextInt(bound)));
                    }
                    return builder.toString();
                }
            )
        );
    }
}

@@ -1316,165 +1316,15 @@
 ble.
-IterableOf;%0Aimport org.cactoos.iterable.RangeOf;%0Aimport org.cactoos.iterable.Shuffled;%0Aimport org.cactoos.iterator.Cycled;%0Aimport org.cactoos.iterator.Sliced
+RangeOf
 ;%0Aim
@@ -3270,33 +3270,25 @@
 @param chrs 
-List of c
+C
 haracters al
@@ -3381,36 +3381,40 @@
 andomized(final 
-List
+Iterable
 %3CCharacter%3E chrs
@@ -3527,38 +3527,29 @@
    * @param 
-chrs List of c
+itr C
 haracters al
@@ -3689,36 +3689,40 @@
 andomized(final 
-List
+Iterable
 %3CCharacter%3E chrs
@@ -3709,36 +3709,35 @@
 able%3CCharacter%3E 
-chrs
+itr
 , final Scalar%3CI
@@ -3832,16 +3832,84 @@
 () -%3E %7B%0A
+                    final List%3CCharacter%3E chrs = new ListOf%3C%3E(itr);%0A
         

Use `Iterable` instead of `List`