Assigning Random Values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
royrogersrevenge
Forum Newbie
Posts: 14
Joined: Fri Apr 06, 2007 9:57 pm

Assigning Random Values

Post by royrogersrevenge »

I'm a bit new and could use some help on something.

I'd like to randomly assign values to entries in a table. How would I do this while ensuring that all values in a certain range(1-16, in this instance) are used and not repeated?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Code: Select all

$numbers = range(1,16); // create an array of numbers
shuffle($numbers); // shuffle the deck
foreach($numbers as $num){
//... 
}
Post Reply