1 Attachment(s)
class module for shuffling an array
hi,
am a newbie to this site n i want to offer whatever little help i can to fellowcoders. here's a small class module to shuffle the elements of an array. this class module comes in handy when you have a problem of shuffling the elements of an array and wish to save some time.
i know many of you know many a better ways of doing such things and i would certainly like to know about them too.
plzz reply about it.
deb..
Re: class module for shuffling an array
Welcome to CodeGuru!
Your shuffle routine looks ok, though it would probably be more efficiant to use a .bas module rather than a class. You could also store the UBound in a variable so it doesn't have to retrieve it each time, which could help a bit for large arrays. I'd also recommend accounting for arrays which use element zero.
Just so you know, Longs are slightly more efficiant than Integers, so it is almost always worth the extra two bytes. That would allow for a much larger array too.
I do like the fact that it doesn't attempt to make sure that all elements get a new index. This is consistant with actual randomness.
Re: class module for shuffling an array
thnx for the suggestions wiz. i would do as u hav suggested. u r obviously right about the long one,yeah i shld've thought of it
anyway thnx again...
deb