Page 1 of 1

Rand variables

Posted: Sun Jul 17, 2011 4:10 pm
by 62896dude
Hello everyone!

This is a pretty basic question, but when calling for a random number in php with rand(x,y), can one substitute x and y for variables, and if so, how would one do it?

Thanks!

Re: Rand variables

Posted: Sun Jul 17, 2011 6:08 pm
by Jackolantern
You can't do it with the basic function, no. But how most developers do something like that is with an array. You fill up the array with whatever variable values you want, and then use the randomly generated number as the index on the array, thus pulling a random value out of it.

Re: Rand variables

Posted: Sun Jul 17, 2011 7:02 pm
by 62896dude
ohhh okay that makes sense, thanks a lot!