Jump to content

array_rand()


Michdd

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.