[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Chaos gurus (oxymoron?),
I have a number of entities (c structures actually), and I have to
randomly re-arrange their order. The randomisation should be without
The method I am using is taken from the book 'C: how to program' (PP
text, I forget the authors. Deitel?). I would like your comments on its
integrity, effectiveness and un-biasness. (wince :)
I know how many structures their are. I malloc space for an array of
pointers to these structures. I initialise the array of pointers to
point to the structures in the order that I read them from a file. Using
a for loop, I go through each and every pointer, in order, and swap it
with another pointer chosen randomly from the array (including itself).
index = rand() % num_structures;
to pick the random index, and I have seeded the randomiser once before
beginning the process using
Any comments appreciated, although please include explainations of your
Don't stress it - it's only 1s and 0s.
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to email@example.com.
If you are having trouble, ask firstname.lastname@example.org for help.
This list is archived at <http://www.progsoc.uts.edu.au/lists/progsoc/>