Skip to content

Commit

Permalink
Add SeqShuffle
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigurd Teigen committed Apr 26, 2013
1 parent 2d96cff commit ef048dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libutils/sequence.c
Expand Up @@ -235,3 +235,10 @@ size_t SeqLength(const Seq *seq)
return seq->length;
}

void SeqShuffle(Seq *seq, unsigned int seed)
{
for (size_t i = 0; i < SeqLength(seq); i++)
{
Swap(&seq->data[rand_r(&seed) % SeqLength(seq)], &seq->data[rand_r(&seed) % SeqLength(seq)]);
}
}
7 changes: 7 additions & 0 deletions libutils/sequence.h
Expand Up @@ -147,4 +147,11 @@ void SeqSoftRemove(Seq *seq, size_t index);
*/
void SeqReverse(Seq *seq);

/**
* @brief Shuffle the sequence by randomly switching positions of the pointers
* @param seq
* @param seed Seed value for the PRNG
*/
void SeqShuffle(Seq *seq, unsigned int seed);

#endif

0 comments on commit ef048dc

Please sign in to comment.