View Full Version : help with the random code
sabret00the
09-25-2003, 07:14 AM
<?php
echo("REQUESTS: ");
$rand[0]=" ";
$rand[1]=" ";
$rand[2]=" ";
$entry = rand(01,19);
echo("$rand[$entry]");
?>
how would i get this to display 5 of the rands at a time and make sure it doesn't repeat any (display the same one twice.
assassingod
09-25-2003, 01:35 PM
Only limit the rand to 5.
rand(1,5)
sabret00the
09-25-2003, 06:13 PM
ok, so cos it's for my site, it will display 5 of my requests at a time randomly not repeating any of em?
assassingod
09-25-2003, 06:19 PM
If you're lucky, it wont repeat.
But after properly reading what you want, it would be easier (and probably the only way) is to use the DB at the backend
Dean C
09-26-2003, 03:55 PM
Tut tut ;):
<?php
echo('REQUESTS: ');
$rand[0] = '';
$rand[1] = '';
$rand[2] = '';
$entry = rand(01, count($rand));
echo("$rand[$entry]");
?>
assassingod
09-26-2003, 04:16 PM
Tut tut ;):
<?php
echo('REQUESTS: ');
$rand[0] = '';
$rand[1] = '';
$rand[2] = '';
$entry = rand(01, count($rand));
echo("$rand[$entry]");
?>
Heh, never knew you could do that.
Dean C
09-26-2003, 05:56 PM
count function counts the number of items in an array :)
assassingod
09-26-2003, 06:09 PM
count function counts the number of items in an array :)
well I knew that I just didnt know you could use it in rand:)
Dean C
09-26-2003, 08:08 PM
An arguement to a a function can be a function you know ;)
I once saw somewhere [I think on php.net] a way to prevent a rand() function from showing the same thing twice...Took a lot of code though.
Dean C
09-28-2003, 10:47 AM
That's cheating though - as it's shuffling not randomizing :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.