Paulinjsh Posted November 8, 2005 Author Report Share Posted November 8, 2005 Nosacījumos bija rakstīts unikāls :P Bet nu es nesaprotu to kāpēc srand izsauc 3 reizes, ja pietiek ar 1? Link to comment Share on other sites More sharing options...
john.brown Posted November 9, 2005 Report Share Posted November 9, 2005 A šitā gadījumā nevar? shuffle($urlArray); $urlArray = array_slice($urlArray,0,3); Link to comment Share on other sites More sharing options...
blackhalt Posted November 9, 2005 Report Share Posted November 9, 2005 (edited) A šitā gadījumā nevar? shuffle($urlArray); $urlArray = array_slice($urlArray,0,3); cik paspaidīju F5 visi ir unikālie ;) <?php $a=glob("images/{*.gif,*.jpg,*.jpeg,*.png}", GLOB_BRACE); shuffle($a); $a=array_slice($a,0,3); echo $a[0].'<br />'; echo $a[1].'<br />'; echo $a[2].'<br />'; ?> Edited November 9, 2005 by blackhalt Link to comment Share on other sites More sharing options...
john.brown Posted November 9, 2005 Report Share Posted November 9, 2005 Tik lai pa visam randomiski strādātu, vajadzētu pirms shuffle() ielikt srand((float)microtime() * 1000000); Link to comment Share on other sites More sharing options...
blackhalt Posted November 9, 2005 Report Share Posted November 9, 2005 Tik lai pa visam randomiski strādātu, vajadzētu pirms shuffle() ielikt srand((float)microtime() * 1000000); Tas ja php vecs. Note: As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically. Link to comment Share on other sites More sharing options...
Recommended Posts