PHP array based on probability returned algorithm

Source: Internet
Author: User
PHP array according to the probability returned algorithm now has a 9 key array: $ arr = array (, 9); I want: 1's return probability is 30% 2's return probability is 20% 3's return probability is 10% 4's return probability is 50% others no matter how such an algorithm calculates it, does this mean? $ ConfigArr PHP array algorithm returned by probability
Now there is a 9-key array:
$ Arr = array (1, 2, 3, 4, 5, 6, 7, 8, 9 );
I hope:
The return probability of 1 is 30%.
The return probability of 2 is 20%.
The return probability of 3 is 10%.
4. The return probability is 50%.
Other
How is this algorithm calculated?


------ Solution --------------------
What does that mean?

$ ConfigArr = array ('20140901', '20160901', '20160901', '20160901 ');

$ Arr = array (1, 2, 3, 4, 5, 6, 7, 8, 9 );
Foreach ($ arr as $ key => $ val)
Echo isset ($ ConfigArr [$ key])? $ Val. 'probability: '. $ ConfigArr [$ key].'
':'';
------ Solution --------------------
Discussion

What does that mean?

$ ConfigArr = array ('20140901', '20160901', '20160901', '20160901 ');

$ Arr = array (1, 2, 3, 4, 5, 6, 7, 8, 9 );
Foreach ($ arr as $ key => $ val)
Echo isset ($ ConfigArr [$ key])? $ Val. 'probability: '. $ ConfigArr [$ key].'
':......

------ Solution --------------------
Discussion

Reference:

What does that mean?

$ ConfigArr = array ('20140901', '20160901', '20160901', '20160901 ');

$ Arr = array (1, 2, 3, 4, 5, 6, 7, 8, 9 );
Foreach ($ arr as $ key => $ val)
Echo isset ($ ConfigArr [$ key])? $ Val. 'probability: '. $ ConfigArr [$ k ......

------ Solution --------------------
Is it true that a number in $ arr = array (, 9); is returned through a function;

The return letter rate is:

The return probability of 1 is 30%.
The return probability of 2 is 20%.
The return probability of 3 is 10%.
4. The return probability is 50%.

!
Is that true?
I have a full idea?
------ Solution --------------------
The numbers are random one by one, for example, 1-random numbers. Returns 1, <= 30, random again, returns 2, <= 20

In short, the number of returned results may exceed 1.
------ Solution --------------------
No .. Soon after I changed my clothes, I was found so quickly ......

Discussion
I wiped it .. The Avatar will also change clothes.


------ Solution --------------------
Agree with amani11.
@ #2 as to whether each number is returned, it is completely an independent event. why should we check whether it is equal to or greater than 100%?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.