this is the pick() function in stdlib