Welcome to WebmasterWorld Guest from 54.196.244.186

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

How do you randomise large chunks of code?

     
10:38 pm on Nov 16, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 25, 2003
posts:2527
votes: 0


I have this:

$item1 = "a really, really, really long chunk of code"
$item2 = "another really, really, really long chunk of code"

$random = '$item1#$item2#$item2#$item2';

$random = explode('#', $random);
shuffle($random);
$random = implode('#', $random);
$random1 = substr($random, 0, strpos($random, '#')).'';

$random2 = '$item1#$item2#$item2#$item2';

$random = explode('#', $random);
shuffle($random);
$random = implode('#', $random);
$random3 = substr($random, 0, strpos($random, '#')).'';

echo $random1;
echo $random3;


which actually prints $item1 or $item2 on the page. It doesn't, (as I'd hoped), display the large chunk of code for each item.
11:36 pm on Nov 16, 2013 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12702
votes: 244


$random = '$item1#$item2#$item2#$item2'

Wouldn't it have to be
$item1 . '#' . $item2 ... et cetera?

What I really wondered though is why you even need to do this. Wouldn't it be more efficient to make each numbered item (is it actually item3, item4 etc or are you mixing three from column B with one from column A?) a separate named function, and just randomize the four names?