diff --git a/src/qsched.c b/src/qsched.c
index 91aeafe740f8642e104ff415aeebc197dd535f71..d54712a92b6937bd900c9e5e461413272fc5f59e 100644
--- a/src/qsched.c
+++ b/src/qsched.c
@@ -832,7 +832,8 @@ struct task *qsched_gettask ( struct qsched *s , int qid ) {
 
     int naq, k, tid, qids[ s->nr_queues ];
     struct task *t;
-    
+    unsigned int seed = qid;
+
     TIMER_TIC
 
     /* Check if the sched is ok. */
@@ -858,7 +859,7 @@ struct task *qsched_gettask ( struct qsched *s , int qid ) {
                     if ( k != qid && s->queues[k].count > 0 )
                         qids[ naq++ ] = k;
                 while ( naq > 0 ) {
-                    k = rand() % naq;
+                    k = rand_r(&seed) % naq;
                     TIMER_TIC2
                     tid = queue_get( &s->queues[ qids[k] ] , s , 0 );
                     TIMER_TOC( s , qsched_timer_queue )