Jump to content

Random Character Genorator


plznty

Recommended Posts

I would like to have a generator that basically creates a certain number of mixed characters.

For example 6 characters which use A and B

It would randomly produce things such as

ABAABA

BABABB

 

I cannot think of any basic ways of achieving this.

Any help would be appreciated even if its written rather than code.

Thank you in advance.

Link to comment
Share on other sites

Try this out Ry4n0wnz...

<?php
  $length = 6;
  $result = '';
  $characters = array('A','B');
  $countArray = (count($characters)-1);

  for($l=0; $l<$length; $l++) {
    $result .= $characters[mt_rand(0,$countArray)];
  }

  echo $result;
?>

 

Tell me how it goes bud :)

 

Regards, Paul.

Link to comment
Share on other sites

function gen_chars($length = 6) {

    // Available characters

    $chars = 'AB';

 

    $Code  = '';

    // Generate code

    for ($i = 0; $i < $length; ++$i)

    {

        $Code .= substr($chars, (((int) mt_rand(0,strlen($chars))) - 1),1);

    }

return $Code;

}

 

// Usage

$var = gen_chars(12);

 

echo $var;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.