Pchp.Library.Arrays.array_rand C# (CSharp) Method

array_rand() public static method

Chooses specified number of keys from an array at random.
Items are chosen uniformly in time O(n), where n is the number of items in the array using conveyor belt sampling.
is a null reference. is not positive and less /// than the number of items in . (Warning)
public static array_rand ( PhpArray array, int count = 1 ) : PhpValue
array Pchp.Core.PhpArray The from which to choose.
count int The number of items to choose.
return Pchp.Core.PhpValue
        public static PhpValue array_rand(PhpArray array, int count = 1)
        {
            if (count == 1)
            {
                var result = new List<PhpValue>(1);
                return RandomSubset(array.Keys, result, count, PhpMath.Generator) ? result[0] : PhpValue.Null;
            }
            else
            {
                var result = new PhpArray(count > 0 ? count : 0);
                if (RandomSubset(array.Keys, result, count, PhpMath.Generator))
                {
                    //result.InplaceCopyOnReturn = true;
                    return PhpValue.Create(result);
                }
                else
                {
                    return PhpValue.Null;
                }
            }
        }