You could use a shuffle operator. Add e.g. the http://projects.ez.no/swark_for_ez_publish_4 extension, and then use the shuffle operator to randomize the order of the $valid_nodes array.
Thank you for your reply, but my meaning is exactly not to use any operator in templates. It is pointless system to return all N items into the valid_nodes array, when it can return only X items; imagine if N is 100 and X is 3, then this is just a waste of resources. If it was up to an operator usage, you do not even need an extra extension to do this with template code.