Rand variables

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
62896dude
Posts: 516
Joined: Thu Jan 20, 2011 2:39 am

Rand variables

Post 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!
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Rand variables

Post 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.
The indelible lord of tl;dr
User avatar
62896dude
Posts: 516
Joined: Thu Jan 20, 2011 2:39 am

Re: Rand variables

Post by 62896dude »

ohhh okay that makes sense, thanks a lot!
Languages: C++, C#, Javascript + Angular, PHP
Programs: Webstorm 2017, Notepad++, Photoshop
Current Project: HP Destiny
Post Reply

Return to “Beginner Help and Support”