Better?
<?php
$args = array('numberposts' => 1, 'category' => 3,'orderby' => 'rand');
$lastposts = get_posts( $args );
if ( false === ( $totd_trans_post_id = get_transient( 'totd_trans_post_id' ) ) ) {
$totd = get_posts($args);
$midnight = strtotime('midnight +1 day');
$timenow = time();
$timetillmidnight = $midnight - $timenow;
echo $midnight;
echo ",".$timenow;
set_transient('totd_trans_post_id', $totd[0]->ID, $timetillmidnight);
} else {
$args = array('post__in' => array($totd_trans_post_id));
$lastposts = get_posts($args);
}
foreach( $lastposts as $post ) : setup_postdata($post); ?>
<div>
<?php the_content(); ?>
</div>
<?php endforeach;
wp_reset_postdata(); ?>