[vox-tech] shuffling arrays in C?

Alexandra Thorn vox-tech@lists.lugod.org
Mon, 25 Nov 2002 11:05:53 -0800 (PST)


I've been looking around for a C library function that will shuffle the
elements of an arbitrarily long array.  I'd been hoping to turn up
something that would randomly shuffle the elements of an array.  The array
that I want to shuffle is made up of a class of structs that I've created.

A few hours of googling and fiddling with the man pages hasn't shed too
much light on the issue: the closest I've found was strfry, which is
supposed to randomize the order of a string.  I'm still a newbie, though,
so maybe don't know where to look.

I suppose that I might be able to hack something up to randomize the order
of an array by using strfry to scramble an array of chars corresponding to
indices, but wanted to check if there is a better way to do this.

Thanks,
Alex

"We must crush in its birth the aristocracy of our moneyed corporations,
which dare already to bid defiance to the laws of our country."
                                        -- Thomas Jefferson, 1812

(Quote courtesy of: http://www.algore04.com Yeah, I know... a democratic
website, but thought the quote was pretty good, assuming it's accurate.)