Michdd Posted November 9, 2008 Share Posted November 9, 2008 As seen here Is it actually 'random' or does it generate by counting a certain entry. For example, I want to create something that will generate a random entry from my array, but I want some things to have a higher likely hood of being picked, so I could just add more than one of those things in the array, but say I placed it in something like this: $input = array("1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", ); If it was generated by counting say every 3rd option it would output 1 a couple of times, then 2 a couple of times, not exactly 'random'. Link to comment https://forums.phpfreaks.com/topic/132018-array_rand/ Share on other sites More sharing options...
Garethp Posted November 9, 2008 Share Posted November 9, 2008 If you are picking only one entry, array_rand() returns the key for a random entry. Otherwise, it returns an array of keys for the random entries. This is done so that you can pick random keys as well as values out of the array. Link to comment https://forums.phpfreaks.com/topic/132018-array_rand/#findComment-685993 Share on other sites More sharing options...
Mchl Posted November 9, 2008 Share Posted November 9, 2008 It's as random as it is possible. See the example on manual page, where there is srand() function used to initiate random number generator. Link to comment https://forums.phpfreaks.com/topic/132018-array_rand/#findComment-685994 Share on other sites More sharing options...
Michdd Posted November 9, 2008 Author Share Posted November 9, 2008 It's as random as it is possible. See the example on manual page, where there is srand() function used to initiate random number generator. So.. $input = array("2", "2", "2", "2", "1", "1", "1", "1"); would generally output the same results as: $input = array("1", "2", "1", "2", "1", "2", "1", "2"); Right? Basically what I'm asking is that if group the same things in the array together, will it still output just as random results as if I mixed them up, inside the array. Link to comment https://forums.phpfreaks.com/topic/132018-array_rand/#findComment-686000 Share on other sites More sharing options...
Mchl Posted November 9, 2008 Share Posted November 9, 2008 Yes. Order is irrevelant. The long run statistics will be the same. Link to comment https://forums.phpfreaks.com/topic/132018-array_rand/#findComment-686021 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.