babaz Posted November 10, 2010 Share Posted November 10, 2010 i wanted to choose 5 random numbers from 0-20. each number represents an index in an array. is there a way to pick out 5 random items from the array. say if random number generator piked a number 22, the last item in the array is at index 20, it wud then have to go to index 0. thanks! Link to comment https://forums.phpfreaks.com/topic/218289-random-number/ Share on other sites More sharing options...
trq Posted November 10, 2010 Share Posted November 10, 2010 Sorry? rand has min & max arguments. Link to comment https://forums.phpfreaks.com/topic/218289-random-number/#findComment-1132610 Share on other sites More sharing options...
salathe Posted November 10, 2010 Share Posted November 10, 2010 You might also like to use array_rand which fetches a specified number of random keys from an array. Link to comment https://forums.phpfreaks.com/topic/218289-random-number/#findComment-1132627 Share on other sites More sharing options...
requinix Posted November 10, 2010 Share Posted November 10, 2010 For picking more than one when duplicates aren't allowed (which you said nothing about but I would still guess so), I prefer shuffle and array_slice. Link to comment https://forums.phpfreaks.com/topic/218289-random-number/#findComment-1132672 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.