l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2002 Nov 25 16:39

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] shuffling arrays in C?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] shuffling arrays in C?

Doesn't sound too tough to write your own algorithm.  For
example you can iterate through your array and swap each 
element in turn with another randomly chosen element.

If the elements are large, it will be helpful (faster) to
build an array of pointers to the elements in the main 
array, and then just shuffle that.

Details are left as an exercise for the reader.  :-)

-- Rod

On Monday 25 November 2002 11:05 am, Alexandra Thorn wrote:
> 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.

vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.