How to randomize published date for WordPress custom post type

You can specify the argument post_type for the function get_posts() (see all available arguments here). So this line

$posts = get_posts( array( 'numberposts' => -1, 'post_status' => 'any' ) );

will become this line

$posts = get_posts( array( 'numberposts' => -1, 'post_status' => 'any', 'post_type' => 'portfolio' ) );