Anonymous Coward User ID: 22653515
United States 11/27/2012 11:14 AM Report Abusive Post Report Copyright Violation | Need help coding some PHP. I need a script that can do a random number 1-3 and based on 1-3 given 3 different echo statements. Can anyone help me? I can't figure out how to get 1-3 as just the random thing gives me an answer like 1.2342342351616 lol and I can't figure out how to extrapolate from there. |
Anonymous Coward (OP) User ID: 22653515
United States 11/27/2012 11:17 AM Report Abusive Post Report Copyright Violation | Re: Need help coding some PHP. Also I have to make sure that each one is displayed, 1-3. |
Anonymous Coward User ID: 28570671 11/27/2012 11:22 AM Report Abusive Post Report Copyright Violation | Re: Need help coding some PHP. hey mate, how about this. [link to stackoverflow.com] |
PsycoCandy
User ID: 9495203
Brazil 11/27/2012 11:25 AM
 Report Abusive Post Report Copyright Violation | Re: Need help coding some PHP. |
pibbsun
User ID: 1312575
United States 11/27/2012 11:28 AM Report Abusive Post Report Copyright Violation | Re: Need help coding some PHP. I'm much more of a ruby guy, but from what I remember of php you could use something like the following:
count = 0
while (count <= 3) { echo rand(1, 3) #may be rand(0,3) can't remember exactly count++ }
I could definitely be wrong with this, may be reading the question wrong. |
Anonymous Coward User ID: 13275147
United States 11/27/2012 11:31 AM Report Abusive Post Report Copyright Violation | Re: Need help coding some PHP. $array = array( 1 => 1, 2 => 2, 3 => 3, );
shuffle ($array); foreach($array as $value){ echo $value; } |
Anonymous Coward (OP) User ID: 22653515
United States 11/27/2012 11:38 AM Report Abusive Post Report Copyright Violation | Re: Need help coding some PHP. $array = array( 1 => 1, 2 => 2, 3 => 3, );
shuffle ($array); foreach($array as $value){ echo $value; }
Quoting: Neoanderthal Man Epic. Much love. :) Working on doing some mind reading as well as at the same time manipulating results on a random number generator. Going to see what I can do. :) |
Anonymous Coward (OP) User ID: 22653515
United States 11/27/2012 11:43 AM Report Abusive Post Report Copyright Violation | Re: Need help coding some PHP. Not quite as good as I had hoped but after a 5 minute meditation:
2 4 5 6 9 10 1 3 7 8
was trying to go odd then even. =\ |
Anonymous Coward (OP) User ID: 22653515
United States 11/27/2012 11:45 AM Report Abusive Post Report Copyright Violation | Re: Need help coding some PHP. Not quite as good as I had hoped but after a 5 minute meditation:
2 4 5 6 9 10 1 3 7 8
was trying to go odd then even. =\
Quoting: Anonymous Coward 22653515 It kinda reversed or something LOL or it's just pure coincidence. |
Anonymous Coward User ID: 15886083
United States 11/27/2012 11:46 AM Report Abusive Post Report Copyright Violation | Re: Need help coding some PHP. Could also use the rand() function. Try this it will pick a number randomly between the first and second parameter 1 and 3 $x = rand(1,3); if ($x == 1) { echo "suck ma ding dong"; } if ($x == 2) { echo "glp has hot babes"; } if ($x == 3) { echo "niburu is fake"; } |
Anonymous Coward (OP) User ID: 22653515
United States 11/27/2012 11:48 AM Report Abusive Post Report Copyright Violation | Re: Need help coding some PHP. Could also use the rand() function. Try this it will pick a number randomly between the first and second parameter 1 and 3
$x = rand(1,3);
if ($x == 1) { echo "suck ma ding dong"; }
if ($x == 2) { echo "glp has hot babes"; }
if ($x == 3) { echo "niburu is fake"; }
Quoting: Anonymous Coward 15886083 Nice take on it. Could also provide some order. |