Jump to content

rand() filter??


mrbean

Recommended Posts

There's no magic solution.  CV has a cool approach.  You could also write a quick function like this.  Rather than asking for explanations of how these work, try reading about the functions used in the php manual.  They are well documented.

 

function getRand() {
  $x = rand(0, 270);
  if ($x > 89 && $x     $x += 180;
  return $x;
}

Link to comment
https://forums.phpfreaks.com/topic/235454-rand-filter/#findComment-1210110
Share on other sites

$range = array_merge(range(0,89),range(181,360));
$number = $range[array_rand($range)];
echo $number;

 

what crayon did there is he created 2 arrays with the min and max so that they excluded the numbers that you want to exclude using the range() function, then he merged those two arrays using the array_merge() function. then using the array_rand() function, this chooses a random number from the array that he merged. then he echoes the chosen number. Not sure if this is what you wanted from an explanation.. ;D

Link to comment
https://forums.phpfreaks.com/topic/235454-rand-filter/#findComment-1210112
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.