Quick Php Question
<div class="IPBDescription">rand() not working?</div>Hello to anyone who knows basic PHP, please humour me. Was trying to get my magic signature to randomly select a background image by using the rand(int1, int2) function. In this case, I'd use rand(1, 2) to select either 'base_image1' or 'base_image2'. Now, I tried adding the rand() function to:
$config['image_base'] = 'base_image';
loads of times, adding it at the back, front, in a different function and then calling it ($rando = rand(1, 2); didn't help). In the end, I just removed the 'base_image' part and it worked ($config['image_base'] = rand(1, 2);), but the curiosity's killing me. How are you supposed to do it?
$config['image_base'] = 'base_image';
loads of times, adding it at the back, front, in a different function and then calling it ($rando = rand(1, 2); didn't help). In the end, I just removed the 'base_image' part and it worked ($config['image_base'] = rand(1, 2);), but the curiosity's killing me. How are you supposed to do it?
Comments
It is, and you do.
It is, and you do. <!--QuoteEnd--> </td></tr></table><span class='postcolor'> <!--QuoteEEnd-->
Seeding random number generation is usually done using the time.
The 'time' function can be used for this.
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. <!--QuoteEnd--></td></tr></table><span class='postcolor'><!--QuoteEEnd-->
<!--c1--></span><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->
$config['image_base'] = 'base_image' . rand(1, 2);
<!--c2--></td></tr></table><span class='postcolor'><!--ec2-->