Newsgroups: sci.math,comp.theory,comp.ai.genetic,comp.ai.alife,comp.ai,comp.ai.neural-nets,sci.math,comp.ai.fuzzy
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!news.mathworks.com!uunet!in1.uu.net!PIT!not-for-mail
From: Bob Wheeler <bwheeler@echip.com>
Subject: Re: Random Permutation
Message-ID: <313CFAD8.4F72@echip.com>
Date: Tue, 05 Mar 1996 21:39:20 -0500
References: <31288A79.41C67EA6@csi.uottawa.ca> <4gjrr8$24k@sleepy.inch.com> <sal.825695548@caolila>
Organization: ECHIP, Inc.
X-Mailer: Mozilla 2.0 (WinNT; I)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 28
Xref: glinda.oz.cs.cmu.edu sci.math:139089 comp.theory:15614 comp.ai.genetic:8220 comp.ai.alife:5203 comp.ai:37523 comp.ai.neural-nets:30315 comp.ai.fuzzy:6929

Steve Linton wrote:
> 
> >I have a different problem... a formula which generates derangements
> >(permutations with no element left unmoved) such that every possible
> >derangement has equal probability (easy enough to modify the above to get
> >derangements, but the prob. is not uniform with the simple mods I have
> >tried... I may have to think about generating a permutation first and
> >then worry about derangements)
> 
> Simply generating random permutations and discarding the ones with
> fied points will do.  Asymptotically 1/e of all permutations is a
> derangement (or is it 1-1/e). Either way, you only take a (smallish)
> constant hit on your running time.
> 
>         Steve Linton


Huh? Perhaps the first fragment is incomplete -- didn't see the
original, but if a derangement is simply a permuation with
all elements moved, wouldn't the following be what is wanted?

X=array of n elements to be deranged
while (n--) {
   int i=rand(n); // Uniform integer from 1 to n
   swap(i,n+1);
}

	Bob Wheeler, ECHIP, Inc.

