Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7050029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:05:37+00:00 2026-05-28T03:05:37+00:00

I have this array: $numbers = array(1, 2, 3); I can grab a random

  • 0

I have this array:

$numbers = array(1, 2, 3);

I can grab a random value from it like so:

$numbers[array_rand($numbers)];

But I need to come up with different random variations of these values. For example

1
13
123
3
32
12
3
12
13
231

etc...

As you can see a number can’t repeat more than once in each set, so we can’t have sets like:

113
232
33

etc...

How can this be done?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:05:37+00:00Added an answer on May 28, 2026 at 3:05 am

    One possible solution is:

    $number1 = array(1, 2, 3);
    $number2 = array(1, 2, 3);
    $number3 = array(1, 2, 3);
    
    $loop = 10;
    for($i=0;$i<$loop;$i++) {
      $bool1 = mt_rand(0, 1);
      $bool2 = mt_rand(0, 1);
    
      $randomNumber = $number1[array_rand($number1)];
      if($bool1)
        $randomNumber .= $number2[array_rand($number2)];
      if($bool2)
        $randomNumber .= $number3[array_rand($number3)];
      echo $randomNumber;
    }
    

    This both randomly decides to choose between 1-3 digits and can use the numbers 1-3 as many times as possible. Just change $loop to the amount of times you want to run the generator.

    I also just realised you could simplify this further:

    $numbers = array(1, 1, 1, 2, 2, 2, 3, 3, 3);
    
    $limit = mt_rand(1, 3);
    $keys = array_rand($numbers, $limit);
    $number = "";
    if($limit == 1)
      $number .= $numbers[$keys];
    else {
      foreach ($keys as $value) {
        $number .= $numbers[$value];
      }
    }  
    

    Insert each number the maximum amount of times into the array you want it to appear in any number (maximum number of digits you want to generate). And randomly generate a number between 1-3 with mt_rand() to use as your array_rand() limit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how i can duplicate one element from array: for example, i have this array:
I have this string of numbers var array = 1,6,2,9,5 which is retrieved from
Lets say I have this array, int[] numbers = {1, 3, 4, 9, 2};
Let's say I have an array like this: $array = array ('1','2','3','4'); And I
I have this huge RegEx for matching credit cards numbers. But its PCRE. Works
I have a 1D numpy array containing complex numbers (eg. numpy.complex64). I need to
I have an array of numbers that can be 1-24. ($timelist) I want to
I have this code, but it won't compile and i can't understand what is
I need to format an array from a list of values. Currently I have
I have array like this: array('1224*', '543*', '321*' ...) which contains about 17,00 "masks"

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.