Port random number generation algrithm on NSArrayExtension.