Page 2 of 2

Posted: Wed Nov 10, 2004 5:31 pm
by timvw
davidjwest wrote: 2. I don't understand "static", (see I did RTFM!)
[php_man]variables.scope[/php_man]
davidjwest wrote: 3. You use a for loop in there but it only generates one random number, when I tried to change the < to a > it didn't execute at all, why use a loop? How would I get this to produce a load of random numbers?
Well, i use a loop to generate the values from 1 to 100, and i store them in an array.

Next i generate 1 random number, as an example how you could use it.
Offcourse you could write your own loop to generate more numbers ;)
davidjwest wrote: 5. I think I answered q3, the return function, I'm used to Basic so this is now confusing the heck out of me, for - return? I guess the whole bit of code is a subroutine so the return jumps out of it? Is that why it executes once?
It executes once because, you only call getLut() once.
Once you have the array that maps number (index of the array) to the given value you can reuse that array.

To generate 10 thingies you want:

Code: Select all

$lut = getLut();
for ($i = 0; $i < 10; ++$i)
{
  echo $lut[rand(1,100)];
}
hth ;)

Posted: Wed Nov 10, 2004 8:26 pm
by rehfeld
this should help you understand for loops

http://php.net/for

btw- if your new to php, your gonna be rtfm'n a lot.

heres a cool bookmarklet

make a bookmark, and use this for the location:

Code: Select all

javascript:q=document.getSelection();if(!q)void(q=prompt('PHP Reference:',''));if(q)location.href='http://www.php.net/'+escape(q)
try it

Re: Random

Posted: Wed Nov 10, 2004 11:19 pm
by Roja
Weirdan wrote: ... unless you have better PRNG (or even real RNG) implemented as stdlib's random function. ;)
Background plays a part here. All the apps I develop generally are deployed by *other people* - so for me, portability trumps special-environment 6 days a week and twice on sundays. (Clearly, your mileage may vary).

Re: Random

Posted: Thu Nov 11, 2004 1:53 pm
by Weirdan
Roja wrote: Background plays a part here. All the apps I develop generally are deployed by *other people*
Apparently you've met your own antipode in me :) Generally I develop app for one certain purpose, to be run in one specific environment (controlled by me). I deploy my apps and mantain it during their entire life-cycle.

Hope together we'll bring balance to these forums :)

Re: Random

Posted: Thu Nov 11, 2004 5:33 pm
by Roja
Weirdan wrote:
Roja wrote: Background plays a part here. All the apps I develop generally are deployed by *other people*
Apparently you've met your own antipode in me :) Generally I develop app for one certain purpose, to be run in one specific environment (controlled by me). I deploy my apps and mantain it during their entire life-cycle.

Hope together we'll bring balance to these forums :)
Heh! Very cool!

Posted: Fri Nov 12, 2004 4:42 pm
by davidjwest
Thanks - again!

:D