CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2005
    Posts
    13

    Talking 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..
    Attached Files Attached Files
    Last edited by pangolin_10; August 2nd, 2005 at 01:21 AM.

  2. #2
    Join Date
    Dec 2001
    Posts
    6,332

    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.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  3. #3
    Join Date
    Jul 2005
    Posts
    13

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured