If single post, for each category of that post, display 5 posts in that category, excluding the single post.
Related:
http://wordpress.org/search/category+single+sidebar?forums=1
http://wordpress.org/support/topic/257858?replies=4
http://wordpress.org/support/topic/179138?replies=4
http://wordpress.org/support/topic/252228
<?php
if ( is_single() ) {
$categories = get_the_category();
if ($categories) {
foreach ($categories as $category) {
$cat = $category->cat_ID;
$args=array(
'cat' => $cat,
'post__not_in' => array($post->ID),
'showposts'=>5,
'orderby'=>'rand',
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo '<h2>More Posts from '. $category->category_description . '</h2>';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
} //if ($my_query)
} //foreach ($categories
} //if ($categories)
wp_reset_query(); // Restore global post data stomped by the_post().
} //if (is_single())
?>
For your category archive, are you suggesting you just want random display of posts in that archive? If so you might try this before your loop:
query_posts($query_string . '&orderby=rand');
Related:
Stepping Into Template Tags
Stepping Into Templates
Template Hierarchy