1

Could you please give me an example how to randomize the repeated string?

Below is my script, it generates a random string from 5-10. After that it gets repeated "1000" times and then I get a output like: "A1B2C3", "A1B2C3", "A1B2C3", but I want unique output like: "B1B3C2", "C3B1A2", "A3B1C2"

Could you please give me an example how to do it, because I am just a beginner and tried a lot before I asked here

<?php      

function generateRandomString() {
    return substr(str_shuffle('@*!"§$%&/()=?ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'), 0, rand(5,10));
}       

while( 1 )
{
    $outstr = str_repeat(generateRandomString(), 1000);                                
    fwrite( $outstr );
}
?>
0

1 Answer 1

1

You need to call generateRandomString() in a loop. You're just calling it once, passing that one string to str_repeat, and it then makes 100 copies of it.

$str = "";
for (i = 0; $i < 100; $i++) {
    $str .= generateRandomString();
}
echo $str;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.