![]() |
Php help needed.
Does someone know how you do this
I'd like to generate 10 random #'s 1 thru 100 and atleast a gap of 4 apart. None can be a duplicate of the other. Anyone know how to do that? Thanks |
Yes, Pay me :1orglaugh
|
hmm basically you just need the rand(1,100) function and you test the result with your conditions...
|
Quote:
|
srand function go read on it at php.net
|
Quote:
I'm assuming he knows how to do while() with conditions...etc...if not then he needs someone to do the script...not some help with it..! ;-) then I could do it...but we get back to the previous point...it's 4am... i'm tired... LOL |
Quote:
jDoG |
Okay this covers your requirements, gives you 10 randomly generated numbers, at least 4 digits away from any other number it previously gave you.
$uniq=array(); function four_or_more_apart($number,$array){ $keys=array_keys($array); for ($x=0; $x<count($keys);$x++){ if ($number-4<$keys[$x] && $number+4>$keys[$x]){ return 0; } } return 1; } while($counter<10){ $number = rand(1,100); if (!$uniq[$number] && four_or_more_apart($number,$uniq)){ $uniq[$number]++; print "$number\n"; $counter++; } } Kind of curious what yah need it for though... |
my beautiful contribution
PHP Code:
|
I want to rotate in random sponsor galleries. I could just hardcode certain spots to be sponsors but I figured doing it random might improve my productivity? Plus new code always helps me somewhere else and I become better at php.
I appreciate the help and when I get going i'll test it out tommorow what was posted. Thanks |
try ghostdriver
|
All times are GMT -7. The time now is 03:46 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123