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! Quote 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. Quote 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. Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/218289-random-number/#findComment-1132672 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.