Say I have a pre-specified set S of m items. I would like to generate a random combination of n (unique) items taken from S.
Is there an easy way to implement this in C? I looked into rand() but it didn't seem to do what I want.
(EDIT to add more details)
The specific problem is to randomly choose n distinct elements from an array of size m. My first instinct is to do this:
idx_array = []
int idx = rand() % m
[if idx not in idx_array, add to idx_array. Otherwise repeat above line. Repeat until idx_array has size n]
But it doesn't look like this process is truly random. I'm still new to C and really just want to know if there's a built-in function for this purpose.
Any help appreciated.