Jump to content

Randomizing


jonoc33

Recommended Posts

Ok, as a joke to a bunch of mates on our forum we added a Water cooler (they requested it) that, if you click it, it adds a session and on the next page and I need it to come up with a random result.

 

Say for example after you click it, on the next page it shows at random 1 of these:

 

"You just drank urine."

"You just ate a bug."

"You feel refreshed."

"Someone took a dump in your cup."

"You found a coin at the bottom of your cup and accidentally drank it."

"Someone spiked your drink. You feel tipsy."

etc.

 

How would I do this?

 

Link to comment
Share on other sites

Put them all into an array and then get a random element:

 

$result=array();
$result[0]="You just drank urine.";
$result[1]="You just ate a bug.";
$result[2]="You feel refreshed.";
$result[3]="Someone took a dump in your cup.";
$result[4]="You found a coin at the bottom of your cup and accidentally drank it.";
$result[5]="Someone spiked your drink. You feel tipsy.";

$random=rand(0, 5);

echo $result[$random];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.