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 7056711
In Process

The Archive Base Latest Questions

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

How to get random value from array set an value in array that will

  • 0

How to get random value from array set an value in array that will be one to selected more than other?

array('00','01','02');

I want to select an random value from this array with most selected value be ’00’, i.e the ’00’ value will be selected 80% and other two values will be 20%.

Here array can have many values, its only an example with three values

  • 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:53:59+00:00Added an answer on May 28, 2026 at 3:53 am
    $main_array=array('00','01','02');
    
    $priority=array(0,0,0,0,0,0,0,0,1,2);
    
    $rand_index=array_rand($priority);//select a random index from priority array.. $priority[$rand_index] will give you index 0 or 1 or 2 with your priority set..
    
    echo $main_array[$priority[$rand_index]];
    

    I think the code is self explanatory…

    Array will have many elements case will come when lets say the requirement will come like 3% probability of “00” 28% prob. of “01” rest to other elements…In that case use array_fill function to fill elements in masses…and array_merge them

    Like for the same case I’ve taken answer will be

    $main_array=array('00','01','02');
    $priority1=array_fill(0,69,2);
    $priority2=array_fill(0,28,1);
    $priority3=array_fill(0,3,0);    
    $priority=array_merge($priority1,$priority2,$priority3);
    
    $rand_index=array_rand($priority);
    
    echo $main_array[$priority[$rand_index]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to select a random value from a array, but keep it unique
What's the fastest way to get a random value from a string array in
I want to get N random numbers whose sum is a value. For example,
I'm running the following code to get a random entry from a dictionary: SELECT
Is there is any way to get the select Random Records using query from
I want to receive an array that contains all the h1 tag values from
What I'm trying to do here is to always get a random value from
I get a random issue with VS2008 (although not that random several times a
How do I get a random decimal.Decimal instance? It appears that the random module
how make special random array. i have array(1=>35,2=>25,3=>40) . how make possibility that array

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.