Re: Random array

New Message Reply About this list Date view Thread view Subject view Author view

Ben Laurie (ben@algroup.co.uk)
Fri, 30 Oct 1998 09:41:52 +0000


Greg Rose wrote:
> I believe the theoretical minimum is O(n log n) *bits* to randomise n
> items. (This agrees entirely with the above, given that the random numbers
> are log n bits each.) But another, theoretically interesting, way to
> randomise is to take a sorting algorithm and make random binary choices
> everywhere it would compare two elements and swap them if out of order.

Beware - quicksort really hates this, and many implementations will
either crash or hang if you don't make consistent decisions. The
preferred approach is to give each thing you want to shuffle a random
number, then sort the random numbers.

Cheers,

Ben.

-- 
Ben Laurie            |Phone: +44 (181) 735 0686| Apache Group member
Freelance Consultant  |Fax:   +44 (181) 735 0689|http://www.apache.org/
and Technical Director|Email: ben@algroup.co.uk |
A.L. Digital Ltd,     |Apache-SSL author     http://www.apache-ssl.org/
London, England.      |"Apache: TDG" http://www.ora.com/catalog/apache/


New Message Reply About this list Date view Thread view Subject view Author view

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

The following archive was created by hippie-mail 7.98617-22 on Sat Apr 10 1999 - 01:15:23