Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,151,153 members, 7,811,306 topics. Date: Sunday, 28 April 2024 at 08:49 AM

A Simple Php Challenge (2) - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / A Simple Php Challenge (2) (876 Views)

How To Create A Simple PHP Website With PBNL Anybody Can Do It! (naijazoom.com) / What Is Wrong With This Simple PHP - MYSQL Script / Another Simple Php/python/asp/etc Challenge (2) (3) (4)

(1) (Reply) (Go Down)

A Simple Php Challenge (2) by elvis10ten(m): 4:11pm On Jul 15, 2013
Write a program that will print out a random number between 0 to 100, with numbers from 0 to 50 having about 80% or more chance of occuring again than numbers from 51 to 100. RULES 1)Run your program in www.ideone.com or post it here if you can't.
2)No dirty brute forcing is allowed.
3)The shortest and fastest code wins.
4)Your code should be able to run on a poor pc. Good luck
Re: A Simple Php Challenge (2) by Z8(m): 9:26am On Jul 16, 2013
/* simulating a 80:100 probability scenerio
which is the same as 4:5 */
$probability = mt_rand(1,5);

/* give numbers 51-100 a 1:5 probability of
occuring */

if($probability == 3){
$random_num = mt_rand(0,50);
}else{
$random_num = mt_rand(51,100);
}

/* $probability is always btw 1-5 ensuring an event happens when its 3 gives it a 1:5 probability */
Re: A Simple Php Challenge (2) by Z8(m): 9:30am On Jul 16, 2013
Z8: /* simulating a 80:100 probability scenerio
which is the same as 4:5 */
$probability = mt_rand(1,5);

/* give numbers 51-100 a 1:5 probability of
occuring */

if($probability == 3){
$random_num = mt_rand(0,50);
}else{
$random_num = mt_rand(51,100);
}

/* $probability is always btw 1-5 ensuring an event happens when its 3 gives it a 1:5 probability */

ideone.com/6E3p6Q
Took 0.01 seconds
Re: A Simple Php Challenge (2) by Nobody: 2:18pm On Jul 16, 2013
--
Re: A Simple Php Challenge (2) by elvis10ten(m): 2:34pm On Jul 16, 2013
Z8:

ideone.com/6E3p6Q
Took 0.01 seconds
you are close to getting the solution but wrong. Look at your code more and check the output.
Re: A Simple Php Challenge (2) by Z8(m): 4:22pm On Jul 16, 2013
elvis10ten: you are close to getting the solution but wrong. Look at your code more and check the output.

/* simulating a 80:100 probability scenerio
which is the same as 4:5 */
$probability = mt_rand(1,5);
/* give numbers 51-100 a 1:5 probability of
occuring */
if($probability == 3){
$random_num = mt_rand(51,100);
}else{
$random_num = mt_rand(0,50);
}
/* $probability is always btw 1-5 ensuring an
event happens when its 3 gives it a 1:5
probability */
Re: A Simple Php Challenge (2) by elvis10ten(m): 4:35pm On Jul 16, 2013
Z8:

/* simulating a 80:100 probability scenerio
which is the same as 4:5 */
$probability = mt_rand(1,5);
/* give numbers 51-100 a 1:5 probability of
occuring */
if($probability == 3){
$random_num = mt_rand(51,100);
}else{
$random_num = mt_rand(0,50);
}
/* $probability is always btw 1-5 ensuring an
event happens when its 3 gives it a 1:5
probability */
Where is your <?php and ?> ?. Where is echo ?. Not because they are common that you need to forget them.
Re: A Simple Php Challenge (2) by Z8(m): 5:52pm On Jul 16, 2013
elvis10ten: Where is your <?php and ?> ?. Where is echo ?. Not because they are common that you need to forget them.
<?php
/* simulating a 80:100 probability scenerio
which is the same as 4:5 */
$probability = mt_rand(1,5);
/* give numbers 51-100 a 1:5 probability of
occuring */
if($probability == 3){
$random_num = mt_rand(0,50);
}else{
$random_num = mt_rand(51,100);
}
/* $probability is always btw 1-5 ensuring an
event happens when its 3 gives it a 1:5
probability */

echo $random_num;
?>
Re: A Simple Php Challenge (2) by elvis10ten(m): 6:45pm On Jul 16, 2013
Z8:
<?php
/* simulating a 80:100 probability scenerio
which is the same as 4:5 */
$probability = mt_rand(1,5);
/* give numbers 51-100 a 1:5 probability of
occuring */
if($probability == 3){
$random_num = mt_rand(0,50);
}else{
$random_num = mt_rand(51,100);
}
/* $probability is always btw 1-5 ensuring an
event happens when its 3 gives it a 1:5
probability */

echo $random_num;
?>
can u get it on www.ideone.com, lets all see the output ?. It would run and its the best and only solution so far.
Re: A Simple Php Challenge (2) by Z8(m): 7:14pm On Jul 16, 2013
ideone.com/Gbt0Db
Re: A Simple Php Challenge (2) by elvis10ten(m): 4:30pm On Jul 22, 2013
Bravo, @ Z8 you won man.

(1) (Reply)

12-year-old Boy Admits To Hacking Police And Government Sites For Anonymous / 10 Reasons Your Seo Rankings Dropped And What To Do About It / Thanks To These Skilled App And Web Developers With Good Human Relationship.

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 19
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.